Skip to content

Commit 31c562a

Browse files
committed
fix: lambda as package + docs
1 parent a2e5012 commit 31c562a

3 files changed

Lines changed: 45 additions & 11 deletions

File tree

skeleton/README.md.jinja

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,47 @@ just lint_full_ff # (fast-fail mode)
3636
just all # (lint + tests)
3737
just all_ff # (lint + tests in fast-fail mode)
3838
```
39-
4039
{%- if is_lambda_project %}
41-
## Deployment to AWS Lambda
42-
1. Package the application:
43-
```bash
44-
just build
45-
```
4640

47-
2. You will see in `/build` directory a zip file ready for deployment to AWS Lambda.
48-
{%- endif %}
41+
## Building and Deployment
42+
43+
### Building the Lambda Package
44+
45+
The project includes a build system that packages the application for AWS Lambda deployment:
46+
47+
```bash
48+
just build
49+
```
50+
51+
This command:
52+
1. Clears the previous build directory (`build/pkg`)
53+
2. Generates a frozen requirements file without dev dependencies
54+
3. Installs all dependencies targeting `x86_64-manylinux2014` platform (compatible with AWS Lambda)
55+
4. Copies the lambda handler shim (`lambda_function.py`) to the package
56+
5. Creates a timestamped zip file in the `build/` directory (e.g., `{{ project_name_snake_case }}_20260201_005935.zip`)
4957

58+
The resulting zip file contains:
59+
- All Python dependencies
60+
- The `{{ source_catalog_name }}` package with your application code
61+
- A `lambda_function.py` shim that exposes the handler
62+
63+
### Lambda Handler Shim
64+
65+
The project uses a shim file (`lambda_function.py`) at the root level to expose the Lambda handler:
66+
67+
This allows AWS Lambda to use the default handler configuration `lambda_function.lambda_handler` while keeping the actual implementation inside the `{{ source_catalog_name }}` package.
68+
69+
**Package Structure:**
70+
```
71+
build/pkg/
72+
├── lambda_function.py # Shim that exposes the handler
73+
├── {{ source_catalog_name }}/
74+
│ ├── __init__.py
75+
│ ├── lambda_function.py # Actual handler implementation
76+
│ └── ...
77+
├── aws_lambda_powertools/
78+
└── ... (other dependencies)
79+
```
80+
81+
**Note:** The shim file can be safely deleted if you update the AWS Lambda **Runtime settings** → **Handler** configuration to point directly to `{{ project_name_snake_case }}.lambda_function.lambda_handler`.
82+
{%- endif %}

skeleton/justfile.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ dc command *args:
109109
[group("lambda_build")]
110110
build: build_create_env
111111
cd {{ BUILD_DIR }}/pkg && \
112-
zip -r ../{% endraw %}{{ source_catalog_name }}{% raw %}_{{ CURRENT_DATETIME }}.zip .
112+
zip -r ../{% endraw %}{{ project_name_snake_case }}{% raw %}_{{ CURRENT_DATETIME }}.zip .
113113

114114
[group("lambda_build")]
115115
build_create_env: clear_build_dir build_generate_requirements build_install copy_shim

skeleton/pyproject.toml.jinja

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ dev = [
2828
"python-dotenv>=1.2.1,<2",
2929
{%- endif %}
3030
]
31-
3231
{%- if is_lambda_project %}
32+
3333
[build-system]
3434
requires = ["hatchling"]
3535
build-backend = "hatchling.build"
36-
{%- endif %}
36+
{%- else %}
3737
3838
[tool.uv]
3939
package = false
40+
{%- endif %}
4041
4142
[tool.ruff]
4243
line-length = 120

0 commit comments

Comments
 (0)