Coder Social home page Coder Social logo

bangpound / aws-codedeploy-new-instance-sync-lambda Goto Github PK

View Code? Open in Web Editor NEW

This project forked from awslabs/aws-codedeploy-new-instance-sync-lambda

0.0 3.0 0.0 1.57 MB

Python script to automatically sync new instances via AWS CodeDeploy APIs

License: Apache License 2.0

Python 100.00%

aws-codedeploy-new-instance-sync-lambda's Introduction

AWS Codedeploy New Instance Sync Lambda

Python script to automatically sync instances via AWS CodeDeploy APIs

License

This library is licensed under the Apache 2.0 License.

Deploying to a new instance with Amazon CodeDeploy, AWS Lambda and AWS Cloudwatch Rule

This architecture provides a set of instructions for deploying code to newly launched EC2 instances using Amazon CodeDeploy with AWS Lambda and AWS Cloudwatch Events

PreRequisite:

You have an existing CodeDeploy application with more than 1 instance in the deployment group. Its also assumed that you have a CodeDeploy Service role already created. You have to update the EC2 instances with CodeDeployGroup and Application Tag

Overview

solution-overview

There is a CloudWatch Events rule which triggers a lambda for every EC2 instance launch. Lambda parses the new instance information and extracts 3 tags โ€“ Name, CodeDeployDeploymentGroup and CodeDeployApplication. Then it adds the EC2 instance to the deployment group obtained from the instance tags. Once added, lambda queries codedeploy to retrieve last successful deployment. Finally, it creates a new deployment with updateOutdatedInstancesOnly flag, so only the new instance added to the deployment group is synchronized with the new code.

Steps

You can launch this CloudFormation stack in the US East (N. Virginia) Region in your account:

cloudformation-launch-stack

Test

Assumption:

  1. You already have couple of instances - CodeDeployDemo and CodeDeployDemo2 as part of your deployment group. They have Name, CodeDeployApplication and CodeDeployDeploymentGroup Tags on them.
  2. You have a successful deployment and have noted the deployment-id

Goal of the Test:

If a new instance with Name, CodeDeployApplication and CodeDeployDeploymentGroup tag gets introduced, it will be added to the respective deployment group. Finally the last successful deployment will be pushed to the new instance

Test Results

New EC2 instance with the appropriate tags is launched

new-instance-launch

Lambda is triggered as evident from the Cloudwatch Logs:

{[ "arn:aws:ec2:us-east-1:xxxxxxxxxxxxxxx:instance/i-00203362b337dd743"] }

Here it is looking up the last deployment id and gets the artifacts associated with that

DepId is d-CSBCXR2GP

Finally, its creates a new deployment to synch the latest instance:

"{u'deploymentId': u'd-W6E1TFFGP', 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '73046797-bb22-11e7-ad7b-25693e030410', 'HTTPHeaders': {'x-amzn-requestid': '73046797-bb22-11e7-ad7b-25693e030410', 'content-length': '30', 'content-type': 'application/x-amz-json-1.1'}}} "

Post lambda run

new-instance-added-to-deployment-group

New instance is synched with the latest deployment

instance-synched-with-latest-code

aws-codedeploy-new-instance-sync-lambda's People

Contributors

ghoshtapo avatar hyandell avatar

Watchers

 avatar  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.