GitHub Action to make zip deployment to AWS Lambda with pip requirements in a separate layer and additional custom layers.
This action automatically installs requirements, zips and deploys the code including the dependencies as a separate layer.
In order for the Action to have access to the code, you must use the actions/checkout@master job before it.
This example workflow assumes your requirements.txt is in the root directory and that your functions are in folders with their function name as the directory name. Custom layers are assumed to be in a directory that matches their custom_layer_N_path value.
The below workflow would publish code to layers (pip and any custom layers) and functions (first_function and second_function), and finally also attach the layers to those updated functions.
For any custom layers, before the files are copied and zipped and uploaded to AWS, any custom script can be executed if it is placed inside the layer folder and named predeploy.sh
Storing credentials as a Github secret is strongly recommended.
- AWS Credentials
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYare required.
requirements_txtThe name/path for therequirements.txtfile. Defaults torequirements.txt.pip_layer_arnThe ARN for the Lambda layer the dependencies should be pushed to without the version (version will be automatically updated on AWS).custom_layer_1_pathSomething like a folder ofutilswhich holds all your utility code.custom_layer_1_arnThe ARN for the Lambda layer where this utility code will go.custom_layer_2_pathSame as above if you need more layers.custom_layer_2_arnSame as above if you need more layers.custom_layer_3_pathSame as above if you need more layers.custom_layer_3_arnSame as above if you need more layers.custom_layer_4_pathSame as above if you need more layers.custom_layer_4_arnSame as above if you need more layers.public_layer_1_arnThe ARN of an external public Lambda layer in case you need one (e.g. https://github.com/keithrozario/Klayers).public_layer_2_arnSame as above if you need more layers.public_layer_3_arnSame as above if you need more layers.public_layer_4_arnSame as above if you need more layers.lambda_function_namesThe Lambda function names comma separated.aws_region
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Deploy code to Lambda
uses: seattleagainstslavery/[email protected]
with:
pip_layer_arn: 'YOUR_UNIQUE_ARN:layer:LAYER_NAME'
custom_layer_1_path: 'utils'
custom_layer_1_arn: 'YOUR_UNIQUE_ARN:layer:LAYER_NAME'
lambda_function_names: 'first_function,second_function'
aws_region: 'us-east-2'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}