Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 2.38 KB

File metadata and controls

63 lines (43 loc) · 2.38 KB

Auto Scaling Group Lifecycle Hooks Example - Lambda Managed Linux

This example solution deploys an Auto Scaling group within a VPC. A lifecycle hook is enabled for the Auto Scaling group and a Lambda Function invokes in response to Lifecycle Action Events. The Lambda function uses AWS Systems Manager to install a sample application onto instances in the Auto Scaling group as they are Launched.

Getting Started

We recommend deploying the following Example AWS Cloud9 Environment to get started quickly with this example. Otherwise, you can attempt to run this example using your own environment with the following prerequisites installed.

Prerequisites

Deployment Steps

Once you've deployed and accessed the Example AWS Cloud9 Environment execute the following steps from within the Example AWS Cloud9 Environment to deploy this example.

  1. Create a S3 bucket where we can upload our packaged Lambda functions for deployment.
aws s3 mb s3://BUCKET_NAME
  1. Change directories to this example.
cd ~/environment/amazon-ec2-auto-scaling-group-examples/features/lifecycle-hooks/lambda-managed-linux
  1. Build the solution.
sam build --use-container
  1. Package the solution. You will need to replace REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME with the name of the S3 bucket created in the first step.
sam package \
    --output-template-file packaged.yaml \
    --s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME
  1. Deploy the solution. You will need to replace REPLACE_THIS_WITH_YOUR_KEY_PAIR_NAME with the name of an SSH key in the region you are deploying the example to.
sam deploy \
    --template-file packaged.yaml \
    --stack-name lifecycle-hook-example \
    --capabilities CAPABILITY_IAM \
    --parameter-overrides \
        InstanceKeyPair=REPLACE_THIS_WITH_YOUR_KEY_PAIR_NAME  

Clean Up

  1. Delete the stack.
aws cloudformation delete-stack --stack-name lifecycle-hook-example