An empty SAM template project integrated with the python project structure allowing seemless local development and remote deployment.
DO NOT FORK Use the template
.
├── events # Files for simulated events
│ └── response.json
├── hello_world # Each Lambda function handler in it's own directory
│ ├── app.py # The function handler itself
│ └── requirements.txt # Dependancies of the function hander
├── layers
│ ├── bin # Deployed as a separate Layer
│ │ └── requirements.txt # All shared libaries go here
│ └── project_layer
│ └── python
│ └── project_modules # Built as a pyproject for local development
│ ├── module.py
│ └── requirements.txt # Dependencies of the project_modules
├── tests
│ ├── unit # Functional Unit tests
│ │ └── test_handler.py
│ └── requirements.txt
├── pyproject.toml # Install layers as pyproject for local development
├── README.md
├── requirements.txt # Local development dependencies and imports all project dependancies
└── template.yaml # Define your SAM resources
Create new SAM project by cloning template into a new local project repository.
git clone https://github.com/m6freeman/sam-python-lambda-layer-template my_sam_project
cd my_sam_project; rm -rf .git; git init
project_description
python -m venv .venv
. ./.venv/bin/activate
pip install -r requirements.txt
# pyproject.toml
[tool.setuptools.packages.find]
where = ["layers/project_layer/python/"]
include = ["project_modules"]
[project]
name = "project_modules"
pip install -e .
# template.yaml
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
CodeUri: hello_world
Description: Hello World function
Architectures:
- x86_64
Tracing: Active
Layers:
- !Ref ProjectLayer
- !Ref ProjectLibraryLayer
# requirements.txt
-r layers/project_layer/python/project_modules/requirements.txt
-r layers/bin/requirements.txt
-r hello_world/requirements.txt
aws-sam-cli
# layers/bin/requirements.txt
aws-lambda-powertools
boto3
result
...
sam build
sam deploy --guided