Skip to content

Build Python Lambda

Build Python Lambda

Description

Simple workflow to prepare a zip file with the python code an dependent libraries defined in requirements.txt. The zip file will be saved as a github artifact.

Usefull to deploy an AWS lambda function or layer.

Inputs

name description type required default
python_version

Python version. Check https://github.com/actions/setup-python for valid values

string false 3.12
source_dir

Directory of the Python source code. Should contain the requirements.txt file

string true ""
zip_filename

The zip file to create. It's relativ to the repository root

string false python_package.zip
gh_artifact_name

Name of the artifact to upload

string true ""
gh_artifact_retention_days

Number of days to retain the artifact

number false 30

Usage

jobs:
  job1:
    uses: tx-pts-dai/github-workflows/.github/workflows/lambda-python.yaml@v2
    with:
      python_version:
      # Python version. Check https://github.com/actions/setup-python for valid values
      #
      # Type: string
      # Required: false
      # Default: 3.12

      source_dir:
      # Directory of the Python source code. Should contain the requirements.txt file
      #
      # Type: string
      # Required: true
      # Default: ""

      zip_filename:
      # The zip file to create. It's relativ to the repository root
      #
      # Type: string
      # Required: false
      # Default: python_package.zip

      gh_artifact_name:
      # Name of the artifact to upload
      #
      # Type: string
      # Required: true
      # Default: ""

      gh_artifact_retention_days:
      # Number of days to retain the artifact
      #
      # Type: number
      # Required: false
      # Default: 30

Example

name: Build

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    uses: tx-pts-dai/github-workflows/.github/workflows/lambda-python.yaml@v2
    with:
      python_version: "3.12"
      source_dir: lambdas/first_lambda
      zip_filename: first_lambda.zip
      gh_artifact_name: first_lambda

FAQ