Message Aid

AWS ECS

  • Provide Message Aid with your AWS Account Number
  • We will create a cross account trust with your AWS account allowing you to pull the Agent image

ECR Repository

550846617829.dkr.ecr.us-east-1.amazonaws.com/prod-us-agent:latest

Verify Installation

  1. Docker image should be up and running
  2. curl -XGET http://localhost:5002/health should return 200
  3. The log statement like Received Kernel Heartbeat prod/us should be seen in the logs

Sample Cloud Formation

---
AWSTemplateFormatVersion: '2010-09-09'
Description: |
  The template used to create an ECS Service 
  from the ECS Console.
Parameters:
  MessageAidEcrRoleArn:
    Type: String
    Default: 
Resources:
  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: message-aid-agent-logs
      RetentionInDays: 60
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete
  TaskRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: message-aid-agent-task-role
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
            Action:
              - sts:AssumeRole
  TaskPolicy:
    Type: AWS::IAM::Policy
    Properties:
      PolicyName: api-gateway-task-policy
      Roles:
        - !Ref TaskRole
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Sid: Logs
            Effect: Allow
            Action: 
              - logs:CreateLogStream
              - logs:PutLogEvents
            Resource:
              - !GetAtt LogGroup.Arn
  ECSTask:
    Type: AWS::ECS::TaskDefinition
    Properties:
      Cpu: "512"
      Memory: "1024"
      ExecutionRoleArn: !Ref MessageAidEcrRoleArn
      TaskRoleArn: !GetAtt TaskRole.Arn
      ContainerDefinitions:
        - Image: 550846617829.dkr.ecr.us-east-1.amazonaws.com/prod-us-agent:latest
          Name: message-aid-agent
          Cpu: 512
          Memory: 1024
          Essential: true
          # HealthCheck:
          #   Command: [ "CMD-SHELL", "curl -f http://localhost:5182/health || exit 1"]
          #   Interval: 60
          #   Retries: 3
          #   StartPeriod: 30
          #   Timeout: 5
          PortMappings:
            - AppProtocol: http
              ContainerPort: 5002
              Name: http
              Protocol: tcp
              HostPort: 0
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !Ref LogGroup
              awslogs-region: 'us-east-1'
      Family: "<YOUR FAMILY>"
      NetworkMode: "<YOUR NETWORK>"
      RequiresCompatibilities:
        - "EC2"

  ECSService:
    Type: AWS::ECS::Service
    Properties:
      Cluster: "<YOUR CLUSTER>"
      TaskDefinition: !Ref ECSTask
      LaunchType: EC2
      ServiceName: message-aid-agent
      SchedulingStrategy: REPLICA
      DesiredCount: 1
      LoadBalancers:
      - ContainerName: message-aid-agent
        ContainerPort: 5002
        LoadBalancerName: !Ref AWS::NoValue
        TargetGroupArn: !Ref TargetGroup
      HealthCheckGracePeriodSeconds: '10'
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
        DeploymentCircuitBreaker:
          Enable: true
          Rollback: true
      DeploymentController:
        Type: ECS
      ServiceConnectConfiguration:
        Enabled: false
      PlacementStrategies:
      - Field: attribute:ecs.availability-zone
        Type: spread
      - Field: instanceId
        Type: spread
      PlacementConstraints: []
      Tags: []
      EnableECSManagedTags: true