Skip to content

Ubuntu-based Docker image with Python 3, aws-cli and serverless framework

Notifications You must be signed in to change notification settings

trina24/aws-sls-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

aws-sls-python

Ubuntu-based Docker image with Python 3.7, aws-cli and serverless framework

Use case

This image allows to deploy Python applications based on serverless framework to AWS.

Using Ubuntu image as base solves the issue with installing Python packages for Lambda functions. Some packages (like psycopg2) installed on Alpine-based images are not working properly on Amazon Linux, which causes Lambda functions to throw errors.

Example

Following code can be used to create a pipeline for GitLab CI/CD EC2 runner that is allowed to assume IAM deployment role.

image: trina24/aws-sls-python:latest

stages:
  - deploy

before_script:
  - ROLE=$(aws sts assume-role --role-arn $DEPLOYMENT_ROLE_ARN --role-session-name $ROLE_SESSION_NAME)
  - export AWS_ACCESS_KEY_ID=$(echo $ROLE | jq .Credentials.AccessKeyId | xargs)
  - export AWS_SECRET_ACCESS_KEY=$(echo $ROLE | jq .Credentials.SecretAccessKey | xargs)
  - export AWS_SESSION_TOKEN=$(echo $ROLE | jq .Credentials.SessionToken | xargs)

.job_template: &deploy
  stage: deploy
  script:
    - sls plugin install -n serverless-python-requirements
    - sls deploy --stage $STAGE

deploy-dev:
  except:
    - master
  variables:
    STAGE: dev
  <<: *deploy

deploy-prod:
  only:
    - master
  variables:
    STAGE: prod
  <<: *deploy

About

Ubuntu-based Docker image with Python 3, aws-cli and serverless framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages