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:
- AWS SNS
- AWS EventBridge
- 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
- Open AWS Console, and navigate to SNS
- Create a topic, give it a name and display name
- Hit “Create topic”
Step 2: Configure EventBridge
- Navigate to EventBridge
- Create EventBridge Rule
- Give it a name and description, make sure it is configured as “Rule with an event pattern”
- In the “Event source” choose “AWS events or EventBridge partner events”
- In the “Creation method” choose “Use pattern from”
- 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"]
}
}
- 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
- Navigate to AWS Chatbot
- Choose Slack as the “Chat client” then “Configure”
- This will take you to Slack’s application OAuth screen
- Configure the Slack channel where you want notifications to go
- Let AWS Console configure the IAM role with the permissions needed
- Choose the SNS topic you created in Step 1
Step 4: Test your integration
- Try to test your integration by stopping a task and see if you are receiving notification as expected or not