Cats task definition

You just created web task definition and the way to define cats task is almost same. The only difference with cats is to configure FireLens, which is a container log router for Amazon ECS to send logs to Amazon CloudWatch Logs.

Because cats have Firelens setting, the configuration is a bit more complicated. It is highly recommended for catsdef to use json template. After you configure via JSON, you may compare the configuration with the screenshopts from 2) Configure via Console section.

1) Create catsdef via JSON template

  1. Move to Amazon ECS Task definition. Click Create new Task Definition
  2. Scroll down to Configure via JSON.
  3. Copy and paste below JSON file.

    You need to correct the region and account ID for your own from the JSON template. You should delete the comments starting with ‘#’ when you paste the template into your console.

{
    "requiresCompatibilities": [
        "EC2"
    ],
    "inferenceAccelerators": [],
    "containerDefinitions": [
        {
        "dnsSearchDomains": null,
        "environmentFiles": null,
        "entryPoint": null,
        "portMappings": [],
        "command": null,
        "linuxParameters": null,
        "cpu": 0,
        "environment": [],
        "resourceRequirements": null,   
        "ulimits": null,
        "dnsServers": null,
        "mountPoints": [],
        "workingDirectory": null,
        "secrets": null,
        "dockerSecurityOptions": null,
        "memory": 128,
        "memoryReservation": null,
        "volumesFrom": [],
        "stopTimeout": null,
        "image": "906394416424.dkr.ecr.ap-northeast-2.amazonaws.com/aws-for-fluent-bit:latest", # Replace 'ap-northeast-2' to your region. 
        "startTimeout": null,
        "firelensConfiguration": {
            "type": "fluentbit",
            "options": null
        },
        "logConfiguration": {
            "logDriver": "awslogs",
            "options": {
                "awslogs-group": "firelens-container",
                "awslogs-region": "ap-northeast-2", # Your region
                "awslogs-create-group": "true",
                "awslogs-stream-prefix": "firelens"
            }
        },
        "dependsOn": null,
        "disableNetworking": null,
        "interactive": null,
        "healthCheck": null,
        "essential": true,
        "links": null,
        "hostname": null,
        "extraHosts": null,
        "pseudoTerminal": null,
        "user": "0",
        "readonlyRootFilesystem": null,
        "dockerLabels": null,
        "systemControls": null,
        "privileged": null,
        "name": "log_router"
        },
        {
        "dnsSearchDomains": null,
        "environmentFiles": null,
        "logConfiguration": {
            "logDriver": "awsfirelens",
            "secretOptions": null,
            "options": {
                "log_group_name": "ecs-demogo-log",
                "auto_create_group": "true",
                "log_stream_prefix": "from-fluent-bit",
                "region": "ap-northeast-2", # Your region
                "Name": "cloudwatch"
            }
        },
        "entryPoint": null,
        "portMappings": [
          {
            "hostPort": 0,
            "protocol": "tcp",
            "containerPort": 80
          }
        ],
        "command": null,
        "linuxParameters": null,
        "cpu": 0,
        "environment": [],
        "resourceRequirements": null,
        "ulimits": null,
        "dnsServers": null,
        "mountPoints": [],
        "workingDirectory": null,
        "secrets": null,
        "dockerSecurityOptions": null,
        "memory": 128,
        "memoryReservation": null,
        "volumesFrom": [],
        "stopTimeout": null,
        "image": "1234567890.dkr.ecr.ap-northeast-2.amazonaws.com/cats:latest", # Replace 1234567890 with your account ID. 
        "startTimeout": null,
        "firelensConfiguration": null,
        "dependsOn": null,
        "disableNetworking": null,
        "interactive": null,
        "healthCheck": null,
        "essential": true,
        "links": null,
        "hostname": null,
        "extraHosts": null,
        "pseudoTerminal": null,
        "user": null,
        "readonlyRootFilesystem": null,
        "dockerLabels": null,
        "systemControls": null,
        "privileged": null,
        "name": "cats"
        }
    ],
    "volumes": [],
    "networkMode": null,
    "memory": null,
    "cpu": null,
    "placementConstraints": [],
    "tags": [],
    "family": "catsdef"
}

2) Configure via Console

If you went through 1) Create catsdef via JSON template, you don’t need to do 2) Configure via Console. Instead, have a look how the configuration looks and review your configuration. Check if you replace correctly with your region and ECR repository URL.

  1. Move to Amazon ECS Task definition to create new.
  2. Select launch type compatibility: EC2
    SelectEC2
  3. Task Definition Name: catsdef

Configure FireLens

Enable FireLens

  1. Scroll down to Log Router Integration and check Enable Firelens Intigration. Select fluentbit and click Apply.

AWS provides a Fluent Bit image with plugins for both CloudWatch Logs and Kinesis Data Firehose. We recommend using Fluent Bit as your log router because it has a lower resource utilization rate than Fluentd. For more information, see CloudWatch Logs for Fluent Bit and Amazon Kinesis Firehose for Fluent Bit.

EnableFireLens

Scroll up to Container Definitions and check if log_router container was created. CheckLogRouter

Log Configuration of log_router container

Click log_router container and scroll down to Advanced container configuration – STORAGE AND LOGGING to configure log.

  1. Log configuration: Uncheck Auto-configure CloudWatch Logs
  2. Log driver and options: LogConfig
  • Log driver: awslogs
  • Log options: Copy and paste is recommended.
Key Value Input
awslogs-group Value firelens-container
awslogs-region Value ap-northeast-2
awslogs-stream-prefix Value firelens
awslogs-create-group Value true
  1. Scroll down to the end and click Update.

Add cats container

Come back to Container Definitions and click Add container to add cats. CatsTask

  1. Configure cats container.
  • Container name: cats
  • Image: your cats latest image URI

Open new browser tab and move to ECR. Select cats repository and click the button of latest tagged image.

CatsLatest

  • Memory Limits - Hard limit 128
  • Port mappings
    • Host port: 0
    • Container port: 80 (tcp)

Log Configuration of cats container

Scroll down to Advanced container configuration – STORAGE AND LOGGING and configure cats container logging.

  1. Log configuration: Uncheck Auto-configure Cloudwatch Logs.
  2. Log driver and options: CatsLogConfig
  • Log driver: awsfirelens
  • Log options
Key Value Input
Name Value cloudwatch
log_group_name Value ecs-demogo-log
log_stream_prefix Value from-fluent-bit
region Value ap-northeast-2
auto_create_group Value true
  1. Click Add then the window closes. Check if cats container added.
  2. Click Create.

You will see how firelens collect and stream your log in Log routing using AWS FireLens.