Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it.
I'm building Node.js Lambda functions using node-lambda that allows for development and testing in a local environment.
In a simple example by adding following bitbucket-pipelines.yml into the project repository my Lambda function gets deployed on every push. I am using environment variables feature to populate $AWS_ACCESS_KEY and $AWS_SECRET_KEY.
image: lambci/lambda:build-nodejs6.10
pipelines:
default:
- step:
script:
- npm install
- npm install node-lambda -g
- node-lambda deploy -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY
caches:
- node
With properly configured node-lambda you will get a green pipeline that indicated successful deployment on a first push:
With the recent addition of Bitbucket Deployments, you can take this solution further and keep track of multiple Lambda environments.
To add deployments tracking with manual production promotion modify YML as follows:
image: lambci/lambda:build-nodejs6.10
pipelines:
default:
- step:
deployment: staging
script:
- npm install
- npm install node-lambda -g
- node-lambda deploy -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY -e staging
caches:
- node
- step:
deployment: production
trigger: manual
script:
- npm install
- npm install node-lambda -g
- node-lambda deploy -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY -e production
caches:
- node
And if everything goes well you should be able to see similar screen to this:
Peter Plewa
2 comments