Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 436
jeremybachtiar Avatar asked Jul 12 '18 04:07

jeremybachtiar


People also ask

How do I access ECS Docker?

To connect to your container instanceOpen the Amazon ECS console at https://console.aws.amazon.com/ecs/ . Select the cluster that hosts your container instance. On the Cluster page, choose ECS Instances. On the Container Instance column, select the container instance to connect to.

Can ECS pull image from Docker hub?

AWS Elastic Container Service (ECS) can pull images from Docker Hub and manage container workload with low-cost AWS Fargate clusters.

What is Awslogs log?

The awslogs log driver can send log streams to an existing log group in CloudWatch Logs or create a new log group on your behalf. The AWS Management Console provides an auto-configure option, which creates a log group on your behalf using the task definition family name with ecs as the prefix.


2 Answers

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

like image 101
Shubham Verma Avatar answered Oct 09 '22 18:10

Shubham Verma


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

like image 2
Sangam Belose Avatar answered Oct 09 '22 18:10

Sangam Belose