Git Product home page Git Product logo

opsworks-lambda-deploy's Introduction

Deploy to OpsWorks using a Lambda function

Requirements

  • AWS OpsWorks

  • Stack Id

  • App Id

  • Running instances

  • AWS Lambda

  • AWS Api Gateway

Lambda function

Create a lambda function that actually connect to OpsWorks and do the deploy

Permissions

We need to create a new role to allow OpsWorks access. Create it and attach the policy with the minimun permissions to deploy, see the file deployOpsworksPolicy.json

Create a new lambda function, assign the recently created role and use the code in index.js The entry point is index.handler

Api Gateway

Then conect your lambda function with the outside world. Assign a new endpoint to your fuction.

Configuration

Create a POST endpoint without authentification. The authentification must be manual, due to bitbucket callback limitations.

Mapping request

Now, we need to map the HTTP request and transform it to event data for out Lambda. To do this, go to the endpoint Integration Request configuration and in Mapping templates create a new one using application/json as content type. Then, modify the template and put this code

$input.json('$')

This will parse the body raw and create a js object that will be the event parameter in the lambda function.

Deploy the API endpoint

After making the deployment of API endpoint, you will have an url like https://das76asdj.execute-api.eu-west-1.amazonaws.com/prod

The final url is that one adding at the end the name of your endpoint, so, for example https://das76asdj.execute-api.eu-west-1.amazonaws.com/prod/deployApi

Note: Take in account, that calling the API to non existing endpoint, or using bad method, return a "Authentification error"

Bitbucket

We already have the Lambda function and the API endpoint that we need to call. Now we need to call this endpoint from Bitbucket each time that we merge a pull request or we make a push to master

Go to the Bitbucket repository setting, to the Webhooks section and add a new one using the url to the lamda function. Choose as triggers

  • Push
  • Pull request merged

Now, every time we merge a pull request or push to master, bitbucket will call our API

opsworks-lambda-deploy's People

Stargazers

Roman avatar Todd Baur avatar

Watchers

James Cloos 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.