Git Product home page Git Product logo

aws-custom-slack-notifications's Introduction

Pushing ECS Task state changes to Slack

test

Description

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)

Setting up

Install Serverless Framework

Use npm to install the framework with npm install serverless -g.

AWS Credentials

For more information visit the following link: https://serverless.com/framework/docs/providers/aws/guide/credentials/.

Policies

Check the following link: https://serverless.com/framework/docs/providers/aws/guide/iam/.

DynamoDB

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.

Policies

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.

Serverless deployment to AWS

  1. clone this repository.
  2. edit serverless.yml with your required info (table name, dynamo endpoint and your slack webhook url)
  3. run npm install to install all required dependencies
  4. deploy the serverless function to AWS with sls deploy

Make it listen to ECS

  1. go to your AWS console and navigate to CloudWatch
  2. click on Rules
  3. create a new rule
    • Service Name: EC2 Container Service (ECS)
    • Event type: State Change
    • Specific detail type(s): ECS Task State Change
  4. add your lambda function that you deployed earlier as a target

Testing

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.

Logging

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.

Issues

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.

Requirements

aws-custom-slack-notifications's People

Contributors

knoxilla avatar segersniels avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.