-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (87 loc) · 3.08 KB
/
lambda-python-deployment.yaml
File metadata and controls
96 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: lambda-python-deployment-with-github-action
on:
workflow_call:
inputs:
AWS_DEFAULT_REGION:
description: 'Region used to deploy code'
default: 'us-east-1'
type: string
bucket_name:
description: 'Name of the bucket that the code will persist.'
required: true
type: string
lambda_name:
description: 'Name of the lambda that will have code deploying.'
required: true
type: string
secrets:
aws_access_key_id:
required: true
aws_secret_access_key:
required: true
env:
file_name: code-lambda
file_name_zip: code-lambda.zip
jobs:
continuous-integration:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements_tests.txt ]; then pip install -r requirements_tests.txt; fi
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- name: Activate venv
run: |
python -m venv venv
source venv/bin/activate
- name: Create Zipfile archive of Dependencies
run: |
zip -r9 $file_name_zip ./venv/lib/python3.10/site-packages
- name: Add App to Zip file
run: zip -g $file_name_zip -r . -x '*.git*' -x '*.pytest*' -x '*tests*'
- name: Upload zip file artifact
uses: actions/upload-artifact@v3
with:
name: code-lambda
path: code-lambda.zip
continuous-development:
runs-on: ubuntu-latest
needs: [continuous-integration]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ inputs.AWS_DEFAULT_REGION }}
role-duration-seconds: 1200
role-session-name: deploy-lambda
- name: Download Lambda code-lambda.zip
uses: actions/download-artifact@v3
with:
name: code-lambda
- name: Upload to S3
run: |
aws s3 cp $file_name_zip s3://${{inputs.bucket_name}}/${{ github.event.repository.full_name }}/$file_name_zip
- name: Deploy new Lambda
run: |
aws lambda update-function-code --function-name ${{inputs.lambda_name}} --s3-bucket ${{inputs.bucket_name}} --s3-key ${{ github.event.repository.full_name }}/$file_name_zip