Wednesday, October 5, 2022

[SOLVED] EC2 Docker container logs on CloudWatch

Issue

I have a running container on EC2 instance and I would like to populate my logs to CloudWatch in the same region.

I was trying to use this tutorial: href="https://docs.docker.com/config/containers/logging/awslogs/" rel="nofollow noreferrer">https://docs.docker.com/config/containers/logging/awslogs/

However I have an issue related with the timeout of connection, also even though policy allows my ec2 instance to connect to the cloudwatch, when i am trying to describe anything I don't receive any response.

Do You know how to get my logs from docker container running on EC2 to cloudwatch? I have tried multiple tutorials, however wasn't able to do it.


Solution

If the instance has correct permission all you need to pass the following option to your docker run command.

docker run -it --log-driver=awslogs --log-opt awslogs-region=us-west-2     --log-opt awslogs-group=myLogGroup --log-opt awslogs-create-group=true  node:alpine

You can check into aws-console, you will see log group name myLogGroup

As you also mentioned that you are getting timeout, to verify this check the below command.

 curl http://checkip.amazonaws.com

If it's not responding it means the instance does not have internet access and its in private subnet.



Answered By - Adiii
Answer Checked By - Timothy Miller (WPSolving Admin)