A simple AWS Lambda function to send Slack notification when ECS service status changes.
This function is triggered by CloudWatch Events when ECS service status changes.
It sends a Slack notification to a specified channel with the following information.
- Service name
- Cluster name
- Task definition with revision
- Status
- Event name
- Event message
- Time
- Link to the ECS Task
The pipeline is as follows.
- ECS service status changes
- AWS Event Bridge sends a message to AWS Simple Notification Service (SNS)
- SNS sends a message to AWS Lambda
- Lambda function sends a message via Slack Webhook API
You need to create all the resources in the same region. If you have multiple regions, where you have ECS services, you need to create AWS Event Bridge where you pipe all the events from all the regions to one region where you have the Lambda function and SNS topic.
- Author from scratch
- Runtime: Python
- Function code:
lambda_function.py
- Replace the following variables with your own values
CLUSTERNAME
SLACK_WEBHOOK_URL
- Name: Create topic
- Type: Standard
- Protocol: Lambda
- Copy the ARN of the Lambda function
- Rule with Event Pattern
- You find the pattern in
eventbridge-pattern.json
- Target: Select SNS topic and the topic you created in step 4
Now you should be able to see the Slack notification when ECS service status changes.
Image of the notifications:
MIT License. See LICENSE file.