https://github.com/aws-samples/amazon-ecs-firelens-examples?tab=readme-ov-file

Logging 단계

product stress 태그 수정하면서 아래의 단계 구성 하면됨

Dockerfile

FROM public.ecr.aws/aws-observability/aws-for-fluent-bit:init-latest
ADD extra.conf /extra.conf

extra.conf

[INPUT]
  Name              tail
  Tag               app-log
  Path              log/app.log
  Skip_Long_Lines   On
  Refresh_Interval  10
  Rotate_wait       30

[FILTER]
  Name grep
  Match *
  Exclude      log /.*healthcheck.*/
  Exclude      log /.*healthcheck.*
  Exclude      log .*healthcheck.*

[OUTPUT]
  Name              cloudwatch
  Match             app-log
  region            ap-northeast-2
  log_group_name    /wsi/webapp/product
  log_stream_prefix ${ECS_TASK_ID}
  auto_create_group true

taskdef.json

{
    "taskDefinitionArn": "arn:aws:ecs:ap-northeast-2:362708816803:task-definition/wsi-taskdef-product:20",
    "containerDefinitions": [
        {
            "name": "webapp",
            "image": "362708816803.dkr.ecr.ap-northeast-2.amazonaws.com/product:latest",
            "cpu": 256,
            "memory": 1024,
            "memoryReservation": 512,
            "portMappings": [
                {
                    "name": "webapp",
                    "containerPort": 8080,
                    "hostPort": 8080,
                    "protocol": "tcp",
                    "appProtocol": "http"
                }
            ],
            "essential": true,
            "environment": [],
            "mountPoints": [],
            "volumesFrom": [],
            "secrets": [
                {
                    "name": "dbinfo",
                    "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:362708816803:secret:dbsecret-9qJc33"
                }
            ],
            "logConfiguration": {
                "logDriver": "awsfirelens",
                "options": {
                    "log_group_name": "/wsi/webapp/product",
                    "log_stream_prefix": "${ECS_TASK_ID}",
                    "region": "ap-northeast-2",
                    "auto_create_group": "true",
                    "Name": "cloudwatch_logs"
                }
            },
            "healthCheck": {
                "command": [
                    "CMD-SHELL",
                    "curl -f <http://localhost:8080/healthcheck> || exit 1"
                ],
                "interval": 5,
                "timeout": 2,
                "retries": 1,
                "startPeriod": 0
            },
            "systemControls": []
        },
        {
            "name": "log_router",
            "image": "362708816803.dkr.ecr.ap-northeast-2.amazonaws.com/product-log:latest",
            "cpu": 256,
            "memoryReservation": 512,
            "portMappings": [],
            "essential": true,
            "environment": [],
            "mountPoints": [],
            "volumesFrom": [],
            "user": "0",
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "/ecs/ecs-aws-firelens-sidecar-container",
                    "mode": "non-blocking",
                    "awslogs-create-group": "true",
                    "max-buffer-size": "25m",
                    "awslogs-region": "ap-northeast-2",
                    "awslogs-stream-prefix": "task"
                }
            },
            "systemControls": [],
            "firelensConfiguration": {
                "type": "fluentbit",
                "options": {
                    "config-file-type": "file",
                    "config-file-value": "/extra.conf",
                    "enable-ecs-log-metadata": "true"
                }
            }
        }
    ],
    "family": "wsi-taskdef-product",
    "taskRoleArn": "arn:aws:iam::362708816803:role/ecsTaskExecutionRole",
    "executionRoleArn": "arn:aws:iam::362708816803:role/ecsTaskExecutionRole",
    "networkMode": "awsvpc",
    "revision": 20,
    "volumes": [],
    "status": "ACTIVE",
    "requiresAttributes": [
        {
            "name": "ecs.capability.execution-role-awslogs"
        },
        {
            "name": "com.amazonaws.ecs.capability.ecr-auth"
        },
        {
            "name": "ecs.capability.firelens.options.config.file"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
        },
        {
            "name": "com.amazonaws.ecs.capability.logging-driver.awsfirelens"
        },
        {
            "name": "com.amazonaws.ecs.capability.task-iam-role"
        },
        {
            "name": "ecs.capability.container-health-check"
        },
        {
            "name": "ecs.capability.execution-role-ecr-pull"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
        },
        {
            "name": "ecs.capability.task-eni"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
        },
        {
            "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
        },
        {
            "name": "ecs.capability.firelens.fluentbit"
        },
        {
            "name": "ecs.capability.secrets.asm.environment-variables"
        }
    ],
    "placementConstraints": [],
    "compatibilities": [
        "EC2",
        "FARGATE"
    ],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "cpu": "512",
    "memory": "1024",
    "runtimePlatform": {
        "cpuArchitecture": "X86_64",
        "operatingSystemFamily": "LINUX"
    },
    "registeredAt": "2025-01-12T12:51:34.306Z",
    "registeredBy": "arn:aws:iam::362708816803:root",
    "enableFaultInjection": false,
    "tags": []
}

아래의 3개의 부분 유의 깊게 세팅하기

"logConfiguration": {
  "logDriver": "awsfirelens",
  "options": {
    "log_group_name": "/wsi/webapp/product",
    "log_stream_prefix": "${ECS_TASK_ID}",
    "region": "ap-northeast-2",
    "auto_create_group": "true",
    "Name": "cloudwatch_logs"
  }
},

"logConfiguration": {
  "logDriver": "awslogs",
  "options": {
    "awslogs-group": "/ecs/ecs-aws-firelens-sidecar-container",
    "mode": "non-blocking",
    "awslogs-create-group": "true",
    "max-buffer-size": "25m",
    "awslogs-region": "ap-northeast-2",
    "awslogs-stream-prefix": "task"
  }
},

"firelensConfiguration": {
  "type": "fluentbit",
  "options": {
    "config-file-type": "file",
    "config-file-value": "/extra.conf",
    "enable-ecs-log-metadata": "true"
  }
}