Skip to content

Commit 8c18dbf

Browse files
Reorganizing docs files
1 parent 31088da commit 8c18dbf

37 files changed

+1389
-809
lines changed

docs/build_recipes.md

Lines changed: 0 additions & 772 deletions
This file was deleted.

docs/build_recipes/build-with-cdk.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
title: Build with CDK
3+
description: Package Lambda functions using AWS CDK for infrastructure as code
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
The **AWS CDK (Cloud Development Kit)** allows you to define cloud infrastructure using familiar programming languages like Python, TypeScript, or Java. It provides type safety, IDE support, and the ability to create reusable constructs, making it perfect for complex infrastructure requirements and teams that prefer code over YAML.
9+
10+
Learn more at [AWS CDK documentation](https://docs.aws.amazon.com/cdk/){target="_blank"}.
11+
12+
## Basic CDK setup with Python
13+
14+
CDK uses the concept of **Apps**, **Stacks**, and **Constructs** to organize infrastructure. A CDK app contains one or more stacks, and each stack contains constructs that represent AWS resources.
15+
16+
### Project structure
17+
18+
```bash
19+
my-lambda-cdk/
20+
├── app.py # CDK app entry point
21+
├── cdk.json # CDK configuration
22+
├── requirements.txt # CDK dependencies
23+
├── src/
24+
│ └── lambda_function.py # Lambda function code
25+
└── stacks/
26+
└── lambda_stack.py # Stack definition (optional)
27+
```
28+
29+
### Key CDK concepts for Lambda
30+
31+
| Concept | Description | Lambda Usage |
32+
|---------|-------------|--------------|
33+
| **App** | Root construct, contains stacks | Entry point for your Lambda infrastructure |
34+
| **Stack** | Unit of deployment | Groups related Lambda functions and resources |
35+
| **Construct** | Reusable cloud component | Lambda function, API Gateway, DynamoDB table |
36+
| **Asset** | Local files bundled with deployment | Lambda function code, layers |
37+
38+
### Prerequisites
39+
40+
Before starting, ensure you have:
41+
42+
```bash
43+
--8<-- "examples/build_recipes/cdk/basic/setup-cdk.sh"
44+
```
45+
46+
### Basic implementation
47+
48+
=== "app.py"
49+
50+
```python
51+
--8<-- "examples/build_recipes/cdk/basic/app.py"
52+
```
53+
54+
=== "cdk.json"
55+
56+
```json
57+
--8<-- "examples/build_recipes/cdk/basic/cdk.json"
58+
```
59+
60+
=== "requirements.txt"
61+
62+
```txt
63+
--8<-- "examples/build_recipes/cdk/basic/requirements.txt"
64+
```
65+
66+
=== "src/lambda_function.py"
67+
68+
```python
69+
--8<-- "examples/build_recipes/cdk/basic/src/lambda_function.py"
70+
```
71+
72+
=== "build-cdk.sh"
73+
74+
```bash
75+
--8<-- "examples/build_recipes/cdk/basic/build-cdk.sh"
76+
```
77+
78+
### CDK bundling options
79+
80+
CDK provides several ways to handle Lambda function dependencies:
81+
82+
| Method | Description | Best For |
83+
|--------|-------------|----------|
84+
| **Inline bundling** | CDK bundles dependencies automatically | Simple functions with few dependencies |
85+
| **Docker bundling** | Uses Docker for consistent builds | Complex dependencies, cross-platform builds |
86+
| **Pre-built assets** | Upload pre-packaged ZIP files | Custom build processes, CI/CD integration |
87+
| **Lambda Layers** | Separate dependencies from code | Shared dependencies across functions |
88+
89+
### Common CDK commands
90+
91+
```bash
92+
--8<-- "examples/build_recipes/cdk/basic/cdk-commands.sh"
93+
```
94+
95+
## Advanced CDK with multiple stacks
96+
97+
Multi-environment CDK setup with separate stacks, DynamoDB integration, and SQS message processing using BatchProcessor.
98+
99+
=== "stacks/powertools_cdk_stack.py"
100+
101+
```python
102+
--8<-- "examples/build_recipes/cdk/multi-stack/stacks/powertools_cdk_stack.py"
103+
```
104+
105+
=== "cdk.json"
106+
107+
```json
108+
--8<-- "examples/build_recipes/cdk/multi-stack/cdk.json"
109+
```
110+
111+
=== "app_multi_stack.py"
112+
113+
```python
114+
--8<-- "examples/build_recipes/cdk/multi-stack/app_multi_stack.py"
115+
```
116+
117+
=== "src/app/api.py"
118+
119+
```python
120+
--8<-- "examples/build_recipes/cdk/multi-stack/src/app/api.py"
121+
```
122+
123+
=== "src/worker/worker.py"
124+
125+
```python
126+
--8<-- "examples/build_recipes/cdk/multi-stack/src/worker/worker.py"
127+
```
128+
129+
=== "deploy-environments.sh"
130+
131+
```bash
132+
--8<-- "examples/build_recipes/cdk/multi-stack/deploy-environments.sh"
133+
```
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Build with Pants
3+
description: Package Lambda functions using Pants for monorepos and complex projects
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
**Pants** is a powerful build system designed for large codebases and monorepos. It provides incremental builds, dependency inference, and advanced caching mechanisms. Ideal for organizations with complex Python projects that need fine-grained build control and optimization.
9+
10+
## Setup
11+
12+
=== "pants.toml"
13+
14+
```toml
15+
--8<-- "examples/build_recipes/pants/basic_pants/pants.toml"
16+
```
17+
18+
=== "BUILD"
19+
20+
```python
21+
--8<-- "examples/build_recipes/pants/basic_pants/BUILD"
22+
```
23+
24+
=== "app.py"
25+
26+
```python
27+
--8<-- "examples/build_recipes/pants/basic_pants/app_pants.py"
28+
```
29+
30+
=== "build-pants.sh"
31+
32+
```bash
33+
--8<-- "examples/build_recipes/pants/basic_pants/build-pants.sh"
34+
```
35+
36+
## Advanced Pants with multiple targets
37+
38+
Pants excels at managing complex projects with multiple Lambda functions that share dependencies. This approach provides significant benefits for monorepo architectures and microservices.
39+
40+
=== "BUILD"
41+
42+
```python
43+
--8<-- "examples/build_recipes/pants/multi-target/BUILD"
44+
```
45+
46+
=== "app/handler.py"
47+
48+
```python
49+
--8<-- "examples/build_recipes/pants/multi-target/app/handler.py"
50+
```
51+
52+
=== "worker/worker_pants.py"
53+
54+
```python
55+
--8<-- "examples/build_recipes/pants/multi-target/worker/worker_pants.py"
56+
```
57+
58+
=== "build-pants-multi.sh"
59+
60+
```bash
61+
--8<-- "examples/build_recipes/pants/multi-target/build-pants-multi.sh"
62+
```

docs/build_recipes/build-with-pip.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Build with pip
3+
description: Package Lambda functions using pip - simple and universal
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
**pip** is Python's standard package installer - simple, reliable, and available everywhere. Perfect for straightforward Lambda functions where you need basic dependency management without complex workflows.
9+
10+
???+ warning "Cross-platform compatibility"
11+
Always use `--platform manylinux2014_x86_64` and `--only-binary=:all:` flags when building on non-Linux systems to ensure Lambda compatibility. This forces pip to download Linux-compatible wheels instead of compiling from source.
12+
13+
## Basic setup
14+
15+
=== "requirements.txt"
16+
17+
```bash
18+
--8<-- "examples/build_recipes/pip/requirements.txt"
19+
```
20+
21+
=== "app_pip.py"
22+
23+
```python
24+
--8<-- "examples/build_recipes/pip/app_pip.py"
25+
```
26+
27+
=== "build.sh"
28+
29+
```bash
30+
--8<-- "examples/build_recipes/pip/build.sh"
31+
```
32+
33+
## Advanced pip with Lambda Layers
34+
35+
Optimize your deployment by using Lambda Layers for Powertools for AWS:
36+
37+
=== "requirements-layer.txt"
38+
39+
```bash
40+
--8<-- "examples/build_recipes/pip/requirements-layer.txt"
41+
```
42+
43+
=== "requirements-app.txt"
44+
45+
```bash
46+
--8<-- "examples/build_recipes/pip/requirements-app.txt"
47+
```
48+
49+
=== "app_pip.py"
50+
51+
```python
52+
--8<-- "examples/build_recipes/pip/app_pip.py"
53+
```
54+
55+
=== "build-with-layer.sh"
56+
57+
```bash
58+
--8<-- "examples/build_recipes/pip/build-with-layer.sh"
59+
```
60+
61+
## Cross-platform builds
62+
63+
Build packages for different Lambda architectures using platform-specific wheels:
64+
65+
=== "Multi-architecture build"
66+
67+
```bash
68+
--8<-- "examples/build_recipes/pip/build-cross-platform.sh"
69+
```
70+
71+
### Platform compatibility
72+
73+
| Platform Flag | Lambda Architecture | Use Case |
74+
|---------------|-------------------|----------|
75+
| `manylinux2014_x86_64` | x86_64 | Standard Lambda functions |
76+
| `manylinux2014_aarch64` | arm64 | Graviton2-based functions (lower cost) |
77+
78+
???+ tip "Architecture selection"
79+
- **x86_64**: Broader package compatibility, more mature ecosystem
80+
- **arm64**: Up to 20% better price-performance, newer architecture
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: Build with Poetry
3+
description: Package Lambda functions using Poetry for modern dependency management
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
**Poetry** is a modern Python dependency manager that handles packaging, dependency resolution, and virtual environments. It uses lock files to ensure reproducible builds and provides excellent developer experience with semantic versioning.
9+
10+
???+ warning "Cross-platform compatibility"
11+
When building on non-Linux systems, use `pip install` with `--platform manylinux2014_x86_64` and `--only-binary=:all:` flags after exporting requirements from Poetry. This ensures Lambda-compatible wheels are installed.
12+
13+
## Setup Poetry
14+
15+
???+ info "Prerequisites"
16+
- **Poetry 2.0+** required for optimal performance and latest features
17+
- Initialize a new project with `poetry new my-lambda-project` or `poetry init` in existing directory
18+
- Project name in `pyproject.toml` can be customized to match your preferences
19+
- See [Poetry documentation](https://python-poetry.org/docs/basic-usage/){target="_blank"} for detailed project setup guide
20+
21+
=== "pyproject.toml"
22+
23+
```toml
24+
--8<-- "examples/build_recipes/poetry/pyproject.toml"
25+
```
26+
27+
=== "app.py"
28+
29+
```python
30+
--8<-- "examples/build_recipes/poetry/app_poetry.py"
31+
```
32+
33+
=== "build-with-poetry.sh"
34+
35+
```bash
36+
--8<-- "examples/build_recipes/poetry/build-with-poetry.sh"
37+
```
38+
39+
### Alternative: Poetry-only build (not recommended for production)
40+
41+
For development or when cross-platform compatibility is not a concern:
42+
43+
=== "build-poetry-native.sh"
44+
45+
```bash
46+
--8<-- "examples/build_recipes/poetry/build-poetry-native.sh"
47+
```
48+
49+
## Cross-platform builds with Poetry
50+
51+
Build packages for different Lambda architectures by combining Poetry's dependency management with pip's platform-specific installation:
52+
53+
=== "Multi-architecture build"
54+
55+
```bash
56+
--8<-- "examples/build_recipes/poetry/build-poetry-cross-platform.sh"
57+
```
58+
59+
### Poetry build methods comparison
60+
61+
| Method | Cross-platform Safe | Speed | Reproducibility | Recommendation |
62+
|--------|-------------------|-------|-----------------|----------------|
63+
| **Poetry + pip** | ✅ Yes | Fast | High | ✅ Recommended |
64+
| **Poetry native** | ❌ No | Fastest | Medium | ⚠️ Development only |
65+
| **Poetry + Docker** | ✅ Yes | Slower | Highest | ✅ Complex dependencies |
66+
67+
???+ tip "Poetry best practices for Lambda"
68+
- Always use `poetry export` to generate requirements.txt for deployment
69+
- Use `--without-hashes` flag to avoid pip compatibility issues
70+
- Combine with `pip install --platform` for cross-platform builds
71+
- Keep `poetry.lock` in version control for reproducible builds
72+
73+
## Poetry with Docker for consistent builds
74+
75+
Use Docker to ensure consistent builds across different development environments and avoid platform-specific dependency issues.
76+
77+
=== "Dockerfile"
78+
79+
```dockerfile title="Dockerfile.poetry"
80+
--8<-- "examples/build_recipes/poetry/Dockerfile.poetry"
81+
```
82+
83+
=== "build-with-poetry-docker.sh"
84+
85+
```bash
86+
--8<-- "examples/build_recipes/poetry/build-with-poetry-docker.sh"
87+
```

0 commit comments

Comments
 (0)