This tool helps manage Python package dependencies and updates Python versions for AWS Lambda functions.
./update-python-packages - Run the script using this command.
This script creates a VENV file if one does not already exist.
Within the Lambda folder the script will create a new directory called latest-python-version-packages containing:
- A site-packages folder with installed requirements.
- A new requirements.txt
- Copied selected files by the -f option, if found.
The script generates the following structure in the specified Lambda folder:
/latest-python-version-packages/ ├── lib/ │ └── python<NEW_PYTHON_VERSION>/ │ └── site-packages/ ├── requirements.txt
--Note:-- This script does not overwrite existing files in Lambda. User must manually replace packages.
Use ./update-python-packages -h for full usage description.
The path to the current working directory, the old python version used as reference, and the path to requirements file are required If no new Python version is specified, the script defaults to Python 3.12.
-p: Path to the current working Lambda files. Required.-f: Comma-separated list of file paths (like common.py,dynamo.py,etc) that will be copied to the new site-packages directory, if found.-n: New python version to use. Default: py3.12-o: Old python version to replace/update. Required.-r: Path to the requirements file. Required.
-Basic example-
./update_python_packages.sh -p /terraform-app-google-device-management/google_management_lambda -o 3.9 -r /terraform-app-google-device-management/google_management_lambda/packages/requirements.txt" - Only required arguments. No files are copied over. Uses default python version: 3.12 to replace the old 3.9
./update_python_packages.sh -p /terraform-app-google-device-management/google_management_lambda -f dynamo.py,common.py,oomnitza.py -n 3.13 -o 3.10 -r /terraform-app-google-device-management/google_management_lambda/packages/requirements.txt" - Use of all arguments. Multiple files copied over. Uses python 3.13 to replace the old 3.10.
./update_python_packages.sh -f dynamo.py,easy_install.py -v 3.10 - Will fail and provide error messages "Lambda code path (-p) is required", "Requirements path (-r) is required", "Old python version to find and replace (-o) is required"
- Pyenv
Pyenv helps us manage and switch between different versions of Python. Pyenv looks for Python versions from its online repository, installs them, and makes them available on your system.