This PowerShell script creates AWS Lambda layers using Docker or Podman. It supports both Python and Node.js runtimes and allows for package installation either from a list of packages or from a requirements file.
- Supports both Python and Node.js Lambda runtimes
- Uses Docker or Podman for consistent build environments
- Can install packages from a list or a requirements file (requirements.txt for Python, package.json for Node.js)
- Option to create only the ZIP file without uploading to AWS
- Flexible container engine selection (Docker or Podman)
- PowerShell 5.1 or later
- Docker or Podman installed and configured
- AWS CLI installed and configured (if uploading to AWS)
powershell .\create-layer.ps1 -layername <string> -runtime <string> [-packages <string[]>] [-requirementsFile <string>] [-zipOnly] [-containerEngine <string>]layername: The name of the Lambda layer to create.runtime: The AWS Lambda runtime to use (e.g., python3.12, nodejs14.x).packages: List of packages to install (use this orrequirementsFile).requirementsFile: Path to the requirements file (requirements.txt for Python, package.json for Node.js).zipOnly: If specified, only creates the ZIP file without uploading to AWS.containerEngine: Container engine to use: "docker" or "podman" (default).
- Create a Python layer with specific packages:
powershell .\create-layer.ps1 -layername "my-python-layer" -runtime "python3.12" -packages "fastapi","mangum","python-jose" -zipOnly- Create a Node.js layer using a package.json file with Podman:
powershell .\create-layer.ps1 -layername "my-node-layer" -runtime "nodejs14.x" -requirementsFile "path/to/package.json" -containerEngine podman- Create and upload a Python layer to AWS using a requirements.txt file:
powershell .\create-layer.ps1 -layername "my-aws-layer" -runtime "python3.11" -requirementsFile "path/to/requirements.txt"- Ensure you have the necessary permissions to create and upload Lambda layers if using the AWS upload feature.
- The script uses the official AWS SAM build images for consistent environments.
- For Python layers,
__pycache__directories are excluded from the final ZIP file.
Contributions to improve the script are welcome. Please feel free to submit a Pull Request.