lollercoaster
lollercoaster

Reputation: 16513

ECS Fargate NGINX container not showing errors in CloudWatch logs

My nginx Dockerfile:

FROM nginx:1.15.12-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx/nginx.conf /etc/nginx/conf.d

# Forward request logs to Docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
  && ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]

My container from my task definition for ECS:

[
  {
    "name": "nginx",
    "image": "<ECR REPO HERE>",
    "networkMode": "awsvpc",
    "essential": true,
    "portMappings": [
      {
        "containerPort": 80,
        "protocol": "http"
      }
    ],
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-group": "mygroup",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "nginx"
      }
    },
    "essential": true
  }
]

Yet when the task is deployed, it fails, and in CloudWatch I see the following:

enter image description here

I'm very new to ECS / Cloudwatch. How can I see the NGINX errors from the container failing?

Upvotes: 5

Views: 4280

Answers (1)

GNOKOHEAT
GNOKOHEAT

Reputation: 963

  1. you should check ECS_Execution_Role_Policy. it should contains logs permission. like :
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecr:GetAuthorizationToken",
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "*"
        }
    ]
}
  1. you should configure ecs_agent's config for awslogs driver.

this config file path is /etc/ecs/ecs.config in host. this file should be like :

ECS_CLUSTER=test_ecs_cluster
ECS_AVAILABLE_LOGGING_DRIVERS=["awslogs","json-file"]

See :

Here's a document

Upvotes: 3

Related Questions