Skip to content

Instantly share code, notes, and snippets.

@Thaina
Created July 31, 2016 10:34
Show Gist options
  • Save Thaina/4d94a2d0e82776f64b4681bf16294c89 to your computer and use it in GitHub Desktop.
Save Thaina/4d94a2d0e82776f64b4681bf16294c89 to your computer and use it in GitHub Desktop.
Bitbucket Pipeline publish to AWS Lambda with version
image: python:3.5.1
pipelines:
default:
- step:
script: # Modify the commands below to build and test your repository.
- apt-get update
- apt-get install -y zip
- zip -r $BITBUCKET_REPO_SLUG".zip" *
- pip install awscli
- alias=`aws lambda get-alias --function-name $FunctionName --name $BITBUCKET_BRANCH || echo "{}"`
- echo $alias
- set=`echo $alias | python -c 'import sys,json;obj=json.load(sys.stdin);print("update-alias" if obj.get("FunctionVersion",False) else "create-alias");'`
- echo $set
- updated=`aws lambda update-function-code --function-name $FunctionName --publish --zip-file fileb://$BITBUCKET_REPO_SLUG".zip" || echo "{}"`
- echo $updated
- version=`echo $updated | python -c 'import sys,json;obj=json.load(sys.stdin);print(obj.get("Version","\$LATEST"));'`
- echo $version
- aws lambda $set --function-name $FunctionName --function-version $version --name $BITBUCKET_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment