Skip to content

Raise Cloudwatch Alarm if ECS Service status is "Stopped"

0

Hi, I need to raise a cloudwatch alarm if one of my ECS Service Status is turned to Stopped. I tried RunningTaskCount but looks like it has dependency of Container Insights to be enabled. It's difficult to get that done. Is there any way I can check the service status of ECS Service and raise alarm if it goes to "Stopped". Thanks, Abdi

2 Answers
1
Accepted Answer

Hello.

Are all the containers in your ECS service set to "essential=true"?
If so, EventBirdge will be able to catch an event when a container stops.
https://repost.aws/articles/AR8VnJ5IN5R6i2GNYbLwEdxw/how-to-notify-by-email-when-the-exitcode-of-an-ecs-fargate-task-ends-with-a-value-other-than-0

The documentation also recommends setting an alarm on RunningTaskCount, which is included in the Container Insights metrics.
Since it's difficult for you to use Container Insights, I think that if you can't use EventBridge, you would need to create a script using Lambda or something to periodically check the status of your ECS service.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#ECS-ContainerInsights

EXPERT
answered a year ago
EXPERT
reviewed a year ago
0

You can use EventBridge Rules to enable notification. Go to EventBridge > Rules New Rule.

For rule, use JSON event pattern

{
  "source": ["aws.ecs"],
  "detail-type": ["ECS Service Action"],
  "detail": {
    "eventType": ["SERVICE_TASK_STATE_CHANGE"],
    "lastStatus": ["STOPPED"]
  }
}

For target, use a SNS topic when the event is matched. A notification will be sent to SNS. You can either trigger a Lambda function or simply get an email notification.

EXPERT
answered a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.