Guides
Amazon Web Services
Slack notification for ECS task status change

Slack Notifications for ECS Task Status Change

Sometimes, team would like to have more visibility into their application and whether it ever crashes or not. Because Flightcontrol offers zero-downtime infrastructure, and if you correctly configured your autoscaling rules, you might never notice your application is down. Slack notifications might be a good way to get notified in the event of app crashes.

Please note that this instructions in the guide will create alarms when an ECS task changes from Running to Stopped. This will also create alarms during deployments.

This guide depends on 3 different AWS services:

  1. AWS SNS
  2. AWS EventBridge
  3. AWS Chatbot

The idea is to capture events through EventBridge when a task is stopped, send it to SNS topic, and the topic will trigger a Slack notification through the configured AWS Chatbot application configured.

Step 1: Configure SNS

  1. Open AWS Console, and navigate to SNS (opens in a new tab)
  2. Create a topic, give it a name and display name
  3. Hit "Create topic"

Step 2: Configure EventBridge

  1. Navigate to EventBridge (opens in a new tab)
  2. Create EventBridge Rule
  3. Give it a name and description, make sure it is configured as "Rule with an event pattern"
  4. In the "Event source" choose "AWS events or EventBridge partner events"
  5. In the "Creation method" choose "Use pattern from"
  6. You can use the below JSON, and update the cluster name
{
  "source": ["aws.ecs"],
  "detail-type": ["ECS Task State Change"],
  "detail": {
    "lastStatus": ["STOPPED"],
    "clusterArn": ["arn:aws:ecs:us-west-2:123456789:cluster/web-app-123"]
  }
}
  1. When you hit next, in the Target select "AWS service" and choose "SNS topic". Select the topic you created in Step 1

Step 3: Configure AWS Chatbot

  1. Navigate to AWS Chatbot (opens in a new tab)
  2. Choose Slack as the "Chat client" then "Configure"
  3. This will take you to Slack's application OAuth screen
  4. Configure the Slack channel where you want notifications to go
  5. Let AWS Console configure the IAM role with the permissions needed
  6. Choose the SNS topic you created in Step 1

Step 4: Test your integration

  1. Try to test your integration by stopping a task and see if you are receiving notification as expected or not