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
The execution flow of this AWS Lambda function is depicted in the diagram below:
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.
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
- 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
- Define an AWS CodePipeline
- Define the AWS Lambda function, using the code from index.js
- 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"
}
- 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.