Skip to content

Instantly share code, notes, and snippets.

@m8r1x
Forked from abdullah353/.gitlab-ci.yml
Created December 11, 2017 20:01
Show Gist options
  • Save m8r1x/8b5c8267078007984a29b03c2db1fe05 to your computer and use it in GitHub Desktop.
Save m8r1x/8b5c8267078007984a29b03c2db1fe05 to your computer and use it in GitHub Desktop.
Basic skeleton of Gitlab CI integration with AWS Lambda for auto deployments.
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