AWS ECS docker logs to cloudwatch allows us to send container logs to a central log service. So that we can access the application log for debugging.
Bobcares provides solutions to all issues as part of our AWS support services.
Let’s look at how to set up Amazon ECS and CloudWatch Logs in more detail.
AWS ECS docker logs to cloudwatch
Containers make it simple to package and distribute applications, but they are typically run on a shared cluster. Docker provides a log driver that allows us to send container logs to Amazon CloudWatch Logs in order to access application logs for debugging.
The advantages of centralised logging are numerous. Logs do not consume disc space on Amazon EC2 instances, and log services frequently include additional capabilities that are useful for operations.
For example, CloudWatch Logs includes the ability to create metrics filters that can trigger an alarm if there are too many errors, as well as integrations with Amazon Elasticsearch Service and Kibana to allow for powerful queries and analysis.
Steps to configure Amazon ECS and CloudWatch Logs.
Create a CloudWatch Log group
Select Logs from the CloudWatch console menu. Choose Create log group from the Actions menu.
Create an ECS task definition
Follow the below steps to create an ECS task definition
- Go to the ECS control panel.
- Then, select Task Definitions.
- Create a new Task Definition.
- Name the task definition.
- Select Add container.
- Set the name, image, memory, and CPU values for the container.
- Select the awslogs log driver from the Storage and Logging section.
- Set the name of the awslogs-group to the one we chose in step 1.
- Then, set awslogs-region to the region where we execute the task.
- Finally, set the awslogs-stream-prefix to a custom prefix that identifies the set of logs we’re streaming, such as the name of our application.
The awslogs-stream-prefix was added recently to allow us to link a log stream to an ECS task ID and container name. The log stream was previously named with the Docker container ID, making it difficult to associate with the task.
If a log error occurred, there was no easy way to determine which container was causing the issue. To make it easier to associate logs with task containers, the CloudWatch log stream name now includes our custom prefix, the container name, and the task ID.
Run the task
- Select Clusters from the ECS console.
- Choose the Tasks tab after selecting the cluster.
- Select Start a new task. Select the task definition we created in step 2 from the Task definition list.
- Then, select Run Task.Our task will be in the PENDING state.
- To open the detail view, select the task. Refresh the detail view of our task until it reaches the RUNNING state.
Generate logs
NGINX will have already sent an initialization message to the log stream if we’re using the sample task definition. By connecting to the web server we can generate additional log messages .
View the log
We can add a link to the log stream for the task view. Go to the CloudWatch console by clicking the link. The prefix we specified in the task definition, the container name, and the ECS task ID are all included in the log stream name. This makes finding the log stream from the ECS task and the task from the log stream a breeze.
Cleanup
When we’re finished, close the ECS console and remove the log stream from the CloudWatch console.
[Looking for a solution to another query? We are just a click away.]
Conclusion
To sum up, our knowledgeable Support team went over how to set up Amazon ECS and CloudWatch Logs in greater depth.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments