feature: upgrade python version from 3.8 to 3.12 & package lambda code using github action #4
Workflow file for this run
This file contains hidden or 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
name: Build and Package Lambda(s) | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- main | |
- master | |
paths: | |
- files/lambda-artifacts/** | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
pkg: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
lambda-name: ["securityhub-findings-manager"] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Remove old pkg artifacts | |
run: rm -rf files/pkg/ | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
cd files/lambda-artifacts/${{ matrix.lambda-name }} | |
python -m venv venv | |
source venv/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Create Lambda deployment package | |
run: | | |
# Create the package directory | |
pkg_dir="files/pkg/${{ matrix.lambda-name }}" | |
mkdir -p $pkg_dir | |
# Navigate to site-packages | |
cd files/lambda-artifacts/${{ matrix.lambda-name }}/venv/lib/python${{ matrix.python-version }}/site-packages | |
# Removing nonessential files https://github.com/aws-powertools/powertools-lambda-layer-cdk/blob/d24716744f7d1f37617b4998c992c4c067e19e64/layer/Python/Dockerfile#L37 | |
rm -rf boto* && \ | |
rm -rf s3transfer* *dateutil* urllib3* six* jmespath* && \ | |
find . -name '*.so' -type f -exec strip "{}" \; && \ | |
find . -wholename "*/tests/*" -type f -delete && \ | |
find . -regex '^.*\(__pycache__\|\.py[co]\)$' -delete | |
# Package the lambda function | |
cd ../../../../../../../ | |
zip -r $pkg_dir/lambda_function_python${{ matrix.python-version }}.zip . -x 'venv/*' | |
- name: Commit deployment packages | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "Add all Lambda deployment packages" | |
file_pattern: "files/pkg/**/*.zip" |