All Projects → getsocial-rnd → ecs-drain-lambda

getsocial-rnd / ecs-drain-lambda

Licence: Apache-2.0 license
Automation of Draining ECS instances with Lambda, based on Autoscaling Group Lifecycle hooks or Spot Instance Interruption Notices

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to ecs-drain-lambda

Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+17569.64%)
Mutual labels:  lambda, ecs
eks
AWS EKS - kubernetes project
Stars: ✭ 149 (+166.07%)
Mutual labels:  lambda, ec2-spot
herman
Herman is a tool to simplify deployment of AWS Services using ECS and Lambda, and the provisioning of various AWS services.
Stars: ✭ 33 (-41.07%)
Mutual labels:  lambda, ecs
Designing Cloud Native Microservices On Aws
Introduce a fluent way to design cloud native microservices via EventStorming workshop, this is a hands-on workshop. Contains such topics: DDD, Event storming, Specification by example. Including the AWS product : Serverless Lambda , DynamoDB, Fargate, CloudWatch.
Stars: ✭ 131 (+133.93%)
Mutual labels:  lambda, ecs
Bastions On Demand
Create and destroy bastions on demand with Fargate.
Stars: ✭ 54 (-3.57%)
Mutual labels:  lambda, ecs
Eventstormingworkshop
EventStorming workshop, this is a hands-on workshop. Contains such topics: DDD, Event storming, Specification by example. Including the AWS product : Serverless Lambda , DynamoDB, Fargate, CloudWatch.
Stars: ✭ 184 (+228.57%)
Mutual labels:  lambda, ecs
lambda-pure
Pretty, minimal and fast ZSH prompt, with NodeJS version
Stars: ✭ 107 (+91.07%)
Mutual labels:  lambda
aws-nestjs-starter
Serverless, AWS, NestJS, GraphQL and DynamoDB starter
Stars: ✭ 200 (+257.14%)
Mutual labels:  lambda
aws-waf-logger
Log all AWS WAF Matched Rules to S3 and/or Loggly using Serverless
Stars: ✭ 18 (-67.86%)
Mutual labels:  lambda
scanii-lambda
A Sam-Packaged AWS Lambda client to the scanii.com content processing service
Stars: ✭ 25 (-55.36%)
Mutual labels:  lambda
kula
Lightweight and highly extensible .NET scripting language.
Stars: ✭ 43 (-23.21%)
Mutual labels:  lambda
ECS-CommunityEdition
ECS Community Edition "Free & Frictionless"
Stars: ✭ 125 (+123.21%)
Mutual labels:  ecs
cim
CIM takes the pain out of Infrastructure as Code and CloudFormation
Stars: ✭ 51 (-8.93%)
Mutual labels:  lambda
aws-sam-typescript-layers-example
Example project for developing AWS Lambda functions on TypeScript with all goodies: local development, tests, debugging, shared layers (3rd party and your own), and deploy.
Stars: ✭ 168 (+200%)
Mutual labels:  lambda
demo-notes-app
Source for the demo notes app in the Serverless Stack Guide
Stars: ✭ 52 (-7.14%)
Mutual labels:  lambda
GoblinDB
Fear the Goblin! - An amazing, simple and fun database for humans
Stars: ✭ 54 (-3.57%)
Mutual labels:  lambda
amazon-eventbridge-producer-consumer-example
A simple producer/consumer example for Amazon EventBridge. Questions? @jbesw.
Stars: ✭ 49 (-12.5%)
Mutual labels:  lambda
formidable-serverless
Enables use of formidable (node.js module for parsing form data, especially file uploads) in serverless environments.
Stars: ✭ 28 (-50%)
Mutual labels:  lambda
blueauth
🔐 Serverless passwordless authentication. No databases needed. Use in just 1 line in serverless, middleware, express, next.js, and more.
Stars: ✭ 56 (+0%)
Mutual labels:  lambda
serverless-plugin-bespoken
⚡ Serverless plugin to use our bst proxy tool
Stars: ✭ 29 (-48.21%)
Mutual labels:  lambda

ecs-drain-lambda

Based on the original idea from AWS Blog post and GitHub. With the following differences:

  • Autoscaling Hooks events are received via CloudWatch rules, which makes possible having one function for draining many ECS Clusters

  • Serverless Framework based

  • Written in Golang

  • Supports the draining of Spot based ECS instances via Spot Instance Interruption Notice

Why?

When updating AMI for the ECS instances then ASG replaces them without "Draining" , which may cause a short downtime of deployed containers. This function automates the ECS Cluster Instances Drain process.

How does it work?

ecs-drain-lambda function:

  • Receives CloudWatch event:

    • ANY AutoScaling Lifecycle Terminate event ( EC2 Auto Scaling Lifecycle Hooks for autoscaling:EC2_INSTANCE_TERMINATING event should be configured on your ASG ) from CloudWatch Events

    or

    • ANY Spot Instance Interruption Notice. Imporatant, AWS doesn't guarantees that instance will be drained in time, instance could be terminated before the notice arrival.
  • Gets the ID of the instance that has to be terminated

  • Looks for the ECS Cluster name in the UserData in the following format: ECS_CLUSTER=xxxxxxxxx

  • If some ECS Tasks are running on the instance, starts the Drain process

  • Waits for all the ECS Tasks to shutdown

  • Completes Lifecycle Hook, which lets ASG proceed with instance termination

Requirements

  • Serverless Framework

  • Golang

  • GNU Make

  • Configured EC2 Auto Scaling Lifecycle Hooks for autoscaling:EC2_INSTANCE_TERMINATING event on your ASG

    Example CloudFormation resource:

      ASGTerminateHook:
         Type: "AWS::AutoScaling::LifecycleHook"
         Properties:
           AutoScalingGroupName: !Ref ECSAutoScalingGroup
           DefaultResult: "ABANDON"
           HeartbeatTimeout: "900"
           LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING"
    

How to use

  • Clone the repo with git clone

  • Enter the project directory cd ecs-drain-lambda

  • Run make deploy

Note: by default us-east-1 region is selected, if you need to deploy it to the different region you can use sls deploy -v --region ${AWS_REGION}

Limitations

  • Function waits for 15 minutes for Drain to complete and fails with the timeout after

  • If function fails, then the default lifecycle hook action will be triggered (ABANDON or CONTINUE depending on your Hook configuration), either result will end up with eventual instance termination.

    Documentation

      If the instance is terminating, both ABANDON and CONTINUE allow the instance to terminate. However, ABANDON stops any remaining actions, such as other lifecycle hooks, while CONTINUE allows any other lifecycle hooks to complete.
    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].