kdeng / my-blogs

Kefeng's blogs
0 stars 0 forks source link

Troubleshooting ECS issue #24

Open kdeng opened 1 year ago

kdeng commented 1 year ago

Today, I encountered a silly problem that caused an ECS service to not launch in a healthy status because the container doesn't be built with a curl command, which is used in the health check command of Dockerfile. After take a while to troubleshoot the problem, and the issue has been fixed by adding RUN apk --no-cache add curl line into the Dockerfile.

However, I found lots of interesting things during troubleshooting the issue on the AWS.

Firstly, we can attach a session to the container that is running in the Fargate [1], which requires Session Manager Plugin on the local machine [2].

And then, you can run the following command to check if your local environment is ready to attach to the ECS task container [3].


bash <( curl -Ls https://raw.githubusercontent.com/aws-containers/amazon-ecs-exec-checker/main/check-ecs-exec.sh ) <cluster_name> <task_id>

Until now, you would need to run the following command to enable "execute-command" in the cluster, and the command to attach to the running container.


### Enable execute-command
aws ecs update-service --enable-execute-command --cluster <cluster_name> --service <service_name> --region <region>

### Attach to the container
aws ecs execute-command --region <region>  --command "/bin/sh" --interactive --cluster <cluster_id> --container <container_name> --task <task_id>

This is an excellent experience to learn more tools for helping me troubleshoot the ECS service.

[1] https://aws.amazon.com/blogs/containers/new-using-amazon-ecs-exec-access-your-containers-fargate-ec2/ [2] https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html#install-plugin-macos [3] https://github.com/aws-containers/amazon-ecs-exec-checker