This is an AWS CDK project demonstrating how to set up alerting for failing ECS scheduled tasks.
At a high level, this repository consists of the following:
- an ECS cluster with Fargate capacity providers,
- one container hosting application logic within app,
- an ECS Fargate task definition for the container,
- one EventBridge rule invoking the task periodically,
- an SNS topic with a configurable email subscription, and
- another EventBridge rule sending task exit failures to the SNS topic.
The email address for the SNS subscription is configured using env var ALERT_EMAIL_ADDRESS
.
This setup automatically invokes the ECS Fargate task periodically - set to every minute at the time of writing. Whenever the container exits with a common failure code, email will be broadcasted to whichever address is set using env var ALERT_EMAIL_ADDRESS
.
Remember to tear down the infrastructure or disable the task invocation EventBridge rule when this is not actively in use! Otherwise tasks will repeatedly spin up, and SNS will pollute your email inbox with task failure notifications.
This project applies AWS CDK v2. This is a global installation required for development.
To build application and infrastructure code, run
npm run build
To deploy the application and infrastructure to AWS, run
cdk deploy
To delete the application and infrastructure from AWS, run
cdk destroy