GithubHelp home page GithubHelp logo

afajem / aws-codepipeline-executor Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 10.0 69 KB

AWS Lambda Function to start a specified AWS CodePipeline

License: MIT License

JavaScript 100.00%
aws-lambda aws-codepipeline aws-cloudwatch nodejs

aws-codepipeline-executor's Introduction

CodePipeline Executor - An AWS Lambda-based CodePipeline invoker

Why

A key component to a build system is the ability to periodically run the build (and deployment process). AWS CodePipeline currently does not appear to provide this function (at least to the best of my knowledge). AWS however has the building blocks needed to schedule tasks to be periodically executed as well as orchestrating the invocation of AWS services using the AWS SDK. There are two AWS services that provide these functions:

  • AWS Lambda - Allows for a snippet of code to be executed based on a predefined trigger
  • AWS CloudWatch - Provides a mechanism for scheduling tasks to be executed

How does it work?

The execution flow of this AWS Lambda function is depicted in the diagram below:

AWS Lambda call flow

An AWS CloudWatch event rule is defined to specify the schedule that dictates the frequency of invocation. The rule will invoke the AWS Lambda function that has been created, passing in the name of the AWS CodePipeline to be started. The AWS Lambda function will start the CodePipeline represented by the input pipeline name.

Content

The source code is based on a NodeJS package structure and uses NPM to import libraries that facilitate the core functions. The following are the key files needed:

  • src/index.js: The lambda function used to invoke the CodePipeline
  • package.json: Defines the packaging tasks and the npm modules in use

Requirements

  • Need to create an AWS account
  • Need to setup AWS CLI with the credentials of your AWS account
  • NodeJS and NPM need to be installed

Setting up the Components

  1. Define an AWS CodePipeline
  2. Define the AWS Lambda function, using the code from index.js
  3. Create an AWS CloudWatch event rule. The rule should define the frequency of execution through a schedule (fixed rate or Cron expression). The target should be the Lambda function created in Step 2 with the Configure Input having a JSON object containing the configuration object (event input values) of the function. The following is an example configuration:
{   
	"pipelineName": "MyFirstPipeline"
}

Working with the source code

  • Clone or fork this repository
  • Ensure that you've followed the Requirements section above
  • Run npm run build to install dependencies, package the Lambda function and node modules in a zip and finally deploys the Lambda function to AWS using the AWS CLI. Ensure that the AWS Lambda function name matches the name specified in the AWS deployment step in package.json

###License

See LICENSE for further details.

aws-codepipeline-executor's People

Contributors

afajem avatar

Stargazers

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