This project deploys dromedary in AWS Lambda with API Gateway as the interface to demonstrate serverless architecture. It also demonstrates the use of CodePipeline with Lambdas to continuously deliver changes made in the source code in a serverless manner. We've also written a three-part blog series on the topic here: Serverless Delivery: Architecture (Part 1), Serverless Delivery: Bootstrapping the Pipeline (Part 2) and Serverless Delivery: Orchestrating the Pipeline (Part 3).
The application is split into 2 separate parts for deployment:
- API - deployed as a Lambda function using API Gateway for the front end.
- Static Content - deployed into an S3 bucket with website hosting enabled.
config.json file is generated and deployed into the S3 bucket containing the endpoint to use for the API in API Gateway.
The pipeline consists of the following steps:
- commit - a commit in GitHub triggers a new CodePipeline job. The source is downloaded from GitHub and then pushed into an S3 bucket as a zip file.
- npm lambda - a lambda is executed that downloads the source zip file, runs
npm installto get he dependencies and then uploads the source+dependencies to S3 as a tarball.
- gulp lambda(s) - a lambda is executed that downloads the source+dependencies tarball from S3, extracts it, then runs a gulp task
The details of what happens in the gulp task is completely owned by the
gulpfile.js in the source code. This provides decoupling of the pipeline from the app and allows the pipeline template to be used by any gulp project.
Here's a sample of what the pipeline looks like in AWS CodePipeline console:
To integrate with GitHub, AWS CodePipeline uses OAuth tokens. Generate your token at GitHub and ensure you enable the following two scopes:
admin:repo_hook, which is used to detect when you have committed and pushed changes to the repository
repo, which is used to read and pull artifacts from public and private repositories into a pipeline
Or you can launch by using
gulp in this repo:
- PREREQUISITES - You need Node.js installed.
- Install Node.js:
sudo yum install nodejs npm --enablerepo=epel(For OS X, check out nodejs.org)
- Update NPM:
curl -L https://npmjs.org/install.sh | sudo sh
- Install Gulp:
sudo npm install -g gulp
- Install Node.js:
- Download this repo and then run
npm installfirst to install all dependent modules.
- Bring the pipeline up with
gulp pipeline:up --token=XXXXXXXXXXXXXXXXX
- You can run
gulp pipeline:waitto wait for the stack to come up, and then
gulp pipeline:statusto get the outputs and
gulp pipeline:stacksto see what applicaiton stacks the pipeline has currently running.
- To tear everything down, run
- By default, the stack name will be dromedary-serverless. You can change this by passing
--stackName=my-stack-nameto any of the above gulp commands.
To publish pipeline template/lambda changes, run
gulp publish. You may want to choose a different bucket to publish the templates and lambda code to via the
- Tighten up IAM policies in CFN