How to get the log from an application deployed using docker on AWS ecs
You have to create a log group on ECS:
Follow these steps to create your log group-
Step 1: Open the Amazon ECS console at https://console.aws.amazon.com/ecs/
.
Step 2: In the left navigation pane, choose Task Definitions, Create new Task Definition.
Step 3: Choose your compatibility option
and then Next Step.
Step 4: Choose Add container
to begin creating your container definition.
Step 5: In the Storage and Logging section
, for Log configuration choose Auto-configure CloudWatch Logs
.
Step 6: Enter your awslogs log driver options
. For more details, see Specifying a Log Configuration in your Task Definition.
Step 7: Complete the rest of the task definition wizard.
After creating your log view you can see it by using below steps:
Step 1: Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/
.
Step 2: In the navigation pane, choose Logs.
Step 3: For Log Groups, choose the log group to view the streams.
Step 7: For Log Streams, choose the log stream name
to view the log data.
For more details:
In your container definition you need to mention the log configuration. Since Its unclear whether you are creating the ecs cluster using cloudformation / from gui console, I will try to answer for both ways.
1. GUI console:
2. Using cloudformation template:
{ "containerDefinitions": [ { "name": "nodejsApplication", "links": [ "mysql" ], "image": "nodejsApplication", "essential": true, "portMappings": [ { "containerPort": 80, "hostPort": 80 } ], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "awslogs-nodejsApplication", "awslogs-region": "us-west-2", "awslogs-stream-prefix": "awslogs-example" } }, "memory": 500, "cpu": 10 } ] }
For more details please follow Using Awslogs
console.log
prints to STDOUT. A good way to collect this as logs is to use the awslogs log driver. This will route those logs to a CloudWatch Logs stream of your choice. Here is more information on what CloudWatch Logs and how you can use it.