Giter VIP home page Giter VIP logo

patch-automation-with-awscli-bash's Introduction

Purpose

Patching the EC2 instances used by an Autoscaling Group (ASG) once or monthly through automation.

Tools

Automation Document in Systems Manager (SSM), Lambda python functions, Cloudwatch rule, multiple IAM roles through AWS CLI and Bash.

How does it work?

The script allows you to select an ASG and create an Automation Document to patch the ASG's AMI image once or monthly by scheduling a Cloudwatch rule.

Once you run the script, it will ask you to select an existing ASG through prompt, then go through the following steps.

  1. Creating and/or triggering the Lambda GetCurrentAMI to get the ASG's AMI ID and store it in Parameter Store.
  2. Launching a new EC2 from the AMI.
  3. Patching the EC2 - be Linux or Windows.
  4. Stopping the EC2 and creating a new AMI from it. Terminating the EC2.
  5. Creating and/or triggering the Lambda UpdateASG to create a new LC with the new AMI. Updating the ASG to use the new LC.
  6. Creating and/or triggering the Lambda IncreaseASGCapacity to launch a new EC2 using the patched AMI.
  7. Creating and/or triggering the Lambda DecreaseASGCapacity to terminate old EC2.

For Testing

If you don't have an existing ASG and LC (launch configuration) to test the script, you may refer to the following AWS CLI commands to quickly launch one.

Remember to replace the value of image-id, key-name, and vpc-zone-identifier based on your environment.

For example, image-id ami-02a599eb01e3b3c5b is Ubuntu 18.04, ami-0eb941b8e00feef88 is Windows 2019

aws autoscaling create-launch-configuration --launch-configuration-name your-LC-name --image-id ami-02a599eb01e3b3c5b --instance-type t2.micro --key-name your-private-key

aws autoscaling create-auto-scaling-group --auto-scaling-group-name your-asg-name --launch-configuration-name your-LC-name --min-size 1 --max-size 3 --vpc-zone-identifier "subnet-0ef5abe5710992b33,subnet-0ea175e0213db25a9"

patch-automation-with-awscli-bash's People

Contributors

awengine avatar

Stargazers

 avatar

Watchers

 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.