Created
July 15, 2017 11:20
-
-
Save abdullah353/ec9275bbe70434488a75288e60966820 to your computer and use it in GitHub Desktop.
Basic skeleton of Gitlab CI integration with AWS Lambda for auto deployments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:latest | |
before_script: | |
- apt-get update -y # Updating the Ubuntu Docker instance. | |
- python -V # Print out python version for debugging. | |
- apt install -y zip jq | |
- pip install awscli --upgrade --user | |
- export PATH=~/.local/bin:$PATH # Required for awscli. | |
- aws --version # Print out aws cli version for debugging. | |
stages: | |
- test | |
- deploy | |
test: | |
- pip install -r requirements.txt -t ./ # We must download all dependencies in current directory. | |
- python setup.py test | |
variables: | |
LAMBDA_NAME: 'AwsLambdaFunctionName' # Replace it with the name of aws lambda function you want. | |
S3_BUCKET: 'S3BucketName' # Replace it with the name of Bucket that will hold the zip code. | |
LAMBDA_RUNTIME: 'python2.7' | |
LAMBDA_ARN: 'arn:aws:iam::XXXXX:role/XXXXXX' # ARN associated with this lambda function. | |
LAMBDA_HANDLER: 'lambda_function.lambda_handler' # This is default lambda handler. | |
deploy: | |
stage: deploy | |
only: | |
- master # We will run the CD only when something is going to change in master branch. | |
script: | |
- zip -r code.zip . -x \*.pyc *.git* # Archive the code repository. | |
- aws s3 cp code.zip s3://$S3_BUCKET/code.zip # Upload archive into s3. | |
- aws lambda update-function-code --function-name $LAMBDA_NAME --zip-file fileb://code.zip || aws lambda create-function --function-name $LAMBDA_NAME --runtime $LAMBDA_RUNTIME --role $LAMBDA_ARN --handler $LAMBDA_HANDLER --code S3Bucket=$S3_BUCKET,S3Key=code.zip --memory-size 1024 | |
environment: | |
name: master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Woah thanks! I will try this out.