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?
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.
AWS Elastic Container Service (ECS) can pull images from Docker Hub and manage container workload with low-cost AWS Fargate clusters.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With