Devopslife

Straight to the point

Monitor ECS agent uptime using crontab and SNS

The Amazon ECS container agent allows container instances to connect to your cluster. If this agent is down for some reason, deployments to the service won’t be reflected in the instance and can cause discrepancy.
Here is a one-liner to check if ECS agent container is running. If it is not running, we are making use of AWS SNS service to send a notification to a topic.
if [ -z $(docker ps -f “name=ecs-agent” -f “status=running” -q) ]; then /usr/bin/aws –region=us-east-1 sns publish –topic-arn “arn:aws:sns:us-east-1:123456789012:Topicname” –message “ECS Agent is not running in $HOSTNAME.”; fi
Make sure that the instance role has permissions to publish to the required topic and the topic is already configured.

2 Comments

  1. Hi!

    Thanks for this post. My question is how do I install this to the crontab to the EC2 instance that ECS launches whenever I deploy my application?

    Thank you.

    • Unni

      April 23, 2019 at 3:34 pm

      This is applicable only for Ec2 backed ECS cluster and not the fargate ones. If it is EC2, just login to the backend instance and install the crontab.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2019 Devopslife

Theme by Anders NorenUp ↑