An AWS Lambda Function that posts notifications to Slack when changes occur. It checks if a task has been stuck trying to reach it's desired state (running). The function will only post to Slack in the following cases:
- When a task is stuck and isn't able to maintain running state for longer than 10 seconds after 5 failed attempts
- When a new version of a failing task (with over 5 failed attempts) gets deployed
- Whenever a new task gets deployed (if the variable is set to
true
)
Use npm to install the framework with npm install serverless -g
.
For more information visit the following link: https://serverless.com/framework/docs/providers/aws/guide/credentials/.
Check the following link: https://serverless.com/framework/docs/providers/aws/guide/iam/.
Simply create a table on either a dynamodb-local or AWS DynamoDB with id
as it's hash key (S).
You can add an Index for task
(S) if you would like to expand on this function in the future.
If you are using a dynamodb-local container to handle your database you have to make sure the AWS Lambda traffic to your EC2 Instance is allowed. If you are in fact using an AWS DynamoDB you'll have to define a policy so your Lambda function can actualy GET,POST,DELETE and PUT to your database. Check the following link https://serverless.com/framework/docs/providers/aws/guide/iam/ for more information on adding IAM policies to Serverless.
- clone this repository.
- edit
serverless.yml
with your required info (table name, dynamo endpoint and your slack webhook url) - run
npm install
to install all required dependencies - deploy the serverless function to AWS with
sls deploy
- go to your AWS console and navigate to CloudWatch
- click on
Rules
- create a new rule
- Service Name: EC2 Container Service (ECS)
- Event type: State Change
- Specific detail type(s): ECS Task State Change
- add your lambda function that you deployed earlier as a target
Simply go into your cluster and try stopping one of your tasks and see if messages are getting sent to slack. Or try running a test directly through AWS Lambda with a preconfigured test event, like here.
When creating a Lambda function CloudWatch logging for that function gets enabled, so if you have trouble setting up, be sure to check the logs if there's anything wrong.
If you encounter 'Permission Denied' issues make sure that you give the IAM role, that Serverless assigns to the function, has enough permissions or the correct policies to write to your database.