Giter Club home page Giter Club logo

elb-instance-reboot's Introduction

elb-instance-reboot

An AWS lambda function that reboots ELB instances that are out of service. The function can be automatically triggered by a CloudWatch alarm via an SNS topic message.

Prerequisites

  • AWS account with access to: IAM, Lambda, SNS, CloudWatch, ELB, and EC2

The following installed on your local machine (for deployment):

Deployment and Configuration

To deploy and configure the lambda function, run the following commands from the top-level project directory.

Step 1: Deploy the lambda function

Substitute the region of your elb for {region}, e.g. us-west-2

(Note: AWS calls often take a few seconds to return. So we need to bump the lambda function timeout to 60 seconds.)

claudia create --handler elb-instance-reboot.handler --policies policies --timeout 60 --region {region}

Step 2: Create an SNS Topic

aws sns create-topic --name elb-unhealthy-instances

Step 3: Subscribe the lambda function to the SNS Topic

Use the TopicArn value returned from the last step for {topic}. It will be in the form arn:aws:sns:{region}:{owner id}:elb-unhealthy-instances

claudia add-sns-event-source --topic {topic}

Step 4: Configure a CloudWatch alarm

The following command will create a CloudWatch alarm that is triggered when one or more EC2 instances are out of service for more than 1 minute. You can alter the values for threshold, period, and evaluation-periods to suit your needs.

Substitute the name of the load balancer you want to monitor for {elb name}. Substitute the TopicArn value from step 3 for {topic}.

aws cloudwatch put-metric-alarm --alarm-name unhealthy-instances \
 --metric-name UnHealthyHostCount \
 --namespace AWS/ELB \
 --statistic Minimum \
 --period 60 \
 --threshold 1 \
 --comparison-operator GreaterThanOrEqualToThreshold \
 --evaluation-periods 1 \
 --alarm-actions {topic} \
 --dimensions "Name=LoadBalancerName,Value={elb name}" 

If you have multiple load balancers that you want to monitor, set a separate alarm for each one. These alarms can all point to the same SNS Topic and utilize the same lambda function.

Test

You can confirm that the service is working by manually taking one of your EC2 instances out of service, e.g. by logging in and killing the service that responds to the healthcheck endpoint.

Monitoring

You can subscribe to the SNS topic via email to be notified when the alarm is triggered.

To see the results of any executions of the lambda function, look at the /aws/lambda/elb-instance-reboot log group under Cloudwatch Logs.

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.