jeremybachtiar
jeremybachtiar

Reputation: 81

How to get the log from an application deployed using docker on AWS ecs

I have a backend application running on node.js with feathers.js framework. I have deployed it using docker and it is currently maintained by AWS ECS.

In my application, I have a few lines of 'console.log' to display some Strings for debugging purposes. I am wondering when I have deployed the application on AWS ECS, where is console.log printed to and how do I access it?

Upvotes: 8

Views: 12181

Answers (3)

Sangam Belose
Sangam Belose

Reputation: 4506

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:

AWS Log Configuration In Task definition

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

Upvotes: 2

Shubham Verma
Shubham Verma

Reputation: 9961

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:

Working with Log Groups and Log Streams

Using the awslogs Log Driver

Upvotes: 5

Eric M. Johnson
Eric M. Johnson

Reputation: 7347

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.

Upvotes: 0

Related Questions