vybekiit 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/bin.js +1697 -562
  2. package/dist/global-skills/add-ai/SKILL.md +1 -1
  3. package/dist/global-skills/add-analytics/SKILL.md +1 -1
  4. package/dist/global-skills/add-blog/SKILL.md +1 -1
  5. package/dist/global-skills/add-crud/SKILL.md +1 -1
  6. package/dist/global-skills/add-files/SKILL.md +1 -1
  7. package/dist/global-skills/add-images/SKILL.md +1 -1
  8. package/dist/global-skills/add-language/SKILL.md +1 -1
  9. package/dist/global-skills/add-notifications/SKILL.md +1 -1
  10. package/dist/global-skills/add-realtime/SKILL.md +1 -1
  11. package/dist/global-skills/add-route/SKILL.md +1 -1
  12. package/dist/global-skills/add-search/SKILL.md +1 -1
  13. package/dist/global-skills/add-signin/SKILL.md +1 -1
  14. package/dist/global-skills/add-teams/SKILL.md +1 -1
  15. package/dist/global-skills/add-upload/SKILL.md +1 -1
  16. package/dist/global-skills/aws-serverless/SKILL.md +44 -44
  17. package/dist/global-skills/aws-serverless/assets/powertools-handler.py +1 -2
  18. package/dist/global-skills/aws-serverless/references/api-gateway.md +470 -50
  19. package/dist/global-skills/aws-serverless/references/architecture.md +186 -47
  20. package/dist/global-skills/aws-serverless/references/concurrency.md +158 -44
  21. package/dist/global-skills/aws-serverless/references/deployment.md +1 -1
  22. package/dist/global-skills/aws-serverless/references/event-sources.md +391 -72
  23. package/dist/global-skills/aws-serverless/references/lambda.md +428 -69
  24. package/dist/global-skills/aws-serverless/references/orchestration.md +384 -65
  25. package/dist/global-skills/aws-serverless/references/production.md +415 -78
  26. package/dist/global-skills/aws-serverless/references/troubleshooting.md +626 -79
  27. package/dist/global-skills/back-up-my-code/SKILL.md +1 -1
  28. package/dist/global-skills/buy-domain/SKILL.md +1 -1
  29. package/dist/global-skills/check-safety/SKILL.md +1 -1
  30. package/dist/global-skills/configure-capabilities/SKILL.md +1 -1
  31. package/dist/global-skills/connect-account/SKILL.md +1 -1
  32. package/dist/global-skills/connect-account-backend/SKILL.md +1 -1
  33. package/dist/global-skills/design-my-data/SKILL.md +1 -1
  34. package/dist/global-skills/doctor/SKILL.md +1 -1
  35. package/dist/global-skills/feedback/SKILL.md +63 -0
  36. package/dist/global-skills/go-live/SKILL.md +1 -1
  37. package/dist/global-skills/harden/SKILL.md +1 -1
  38. package/dist/global-skills/instrument-feature-flags/references/usage.md +0 -35
  39. package/dist/global-skills/instrument-product-analytics/SKILL.md +1 -1
  40. package/dist/global-skills/instrument-product-analytics/references/android.md +0 -36
  41. package/dist/global-skills/instrument-product-analytics/references/configuration.md +0 -1
  42. package/dist/global-skills/instrument-product-analytics/references/flutter.md +0 -37
  43. package/dist/global-skills/instrument-product-analytics/references/posthog-python.md +2 -3
  44. package/dist/global-skills/instrument-product-analytics/references/usage.md +0 -35
  45. package/dist/global-skills/manifest.json +2 -1
  46. package/dist/global-skills/neon/SKILL.md +20 -27
  47. package/dist/global-skills/neon-ai-gateway/SKILL.md +2 -68
  48. package/dist/global-skills/neon-functions/SKILL.md +7 -7
  49. package/dist/global-skills/neon-object-storage/SKILL.md +2 -2
  50. package/dist/global-skills/neon-postgres/SKILL.md +5 -5
  51. package/dist/global-skills/neon-postgres-branches/SKILL.md +1 -1
  52. package/dist/global-skills/onboarding/SKILL.md +1 -1
  53. package/dist/global-skills/plan-my-idea/SKILL.md +1 -1
  54. package/dist/global-skills/publish-app/SKILL.md +1 -1
  55. package/dist/global-skills/publish-extension/SKILL.md +1 -1
  56. package/dist/global-skills/reset-password/SKILL.md +1 -1
  57. package/dist/global-skills/save-data/SKILL.md +1 -1
  58. package/dist/global-skills/setup-email/SKILL.md +1 -1
  59. package/dist/global-skills/setup-payments/SKILL.md +1 -1
  60. package/dist/global-skills/setup-sms/SKILL.md +1 -1
  61. package/dist/global-skills/sign-in-with-email-link/SKILL.md +1 -1
  62. package/dist/global-skills/sign-in-with-google/SKILL.md +1 -1
  63. package/dist/global-skills/sign-in-with-phone/SKILL.md +1 -1
  64. package/dist/global-skills/stripe-best-practices/SKILL.md +6 -11
  65. package/dist/global-skills/stripe-best-practices/references/billing.md +0 -5
  66. package/dist/global-skills/stripe-best-practices/references/payments.md +2 -4
  67. package/dist/global-skills/stripe-best-practices/references/tax.md +8 -78
  68. package/dist/global-skills/track-errors/SKILL.md +1 -1
  69. package/dist/global-skills/update-kit/SKILL.md +1 -1
  70. package/dist/global-skills/wire-auth/SKILL.md +1 -1
  71. package/dist/global-skills/wire-database/SKILL.md +1 -1
  72. package/dist/global-skills/wire-email/SKILL.md +1 -1
  73. package/dist/global-skills/wire-payments/SKILL.md +1 -1
  74. package/package.json +8 -8
  75. package/dist/global-skills/email-best-practices/.github/workflows/sync-skills.yml +0 -30
  76. package/dist/global-skills/email-best-practices/README.md +0 -63
  77. package/dist/global-skills/email-best-practices/references/accessibility.md +0 -189
  78. package/dist/global-skills/email-best-practices/references/compliance.md +0 -125
  79. package/dist/global-skills/email-best-practices/references/deliverability.md +0 -121
  80. package/dist/global-skills/email-best-practices/references/email-capture.md +0 -129
  81. package/dist/global-skills/email-best-practices/references/email-types.md +0 -173
  82. package/dist/global-skills/email-best-practices/references/list-management.md +0 -157
  83. package/dist/global-skills/email-best-practices/references/marketing-emails.md +0 -115
  84. package/dist/global-skills/email-best-practices/references/sending-reliability.md +0 -155
  85. package/dist/global-skills/email-best-practices/references/transactional-email-catalog.md +0 -418
  86. package/dist/global-skills/email-best-practices/references/transactional-emails.md +0 -92
  87. package/dist/global-skills/email-best-practices/references/webhooks-events.md +0 -167
  88. package/dist/global-skills/email-best-practices/tests/README.md +0 -35
  89. package/dist/global-skills/email-best-practices/tests/scenarios/01-spam-deliverability.md +0 -46
  90. package/dist/global-skills/email-best-practices/tests/scenarios/02-multi-region-compliance.md +0 -48
  91. package/dist/global-skills/email-best-practices/tests/scenarios/03-retry-idempotency.md +0 -36
  92. package/dist/global-skills/email-best-practices/tests/scenarios/04-webhook-bounce-handling.md +0 -52
  93. package/dist/global-skills/email-best-practices/tests/scenarios/05-new-saas-email-plan.md +0 -51
  94. package/dist/global-skills/neon-postgres/references/neon-sdk.md +0 -262
@@ -1,15 +1,16 @@
1
1
  # AWS Lambda Reference
2
2
 
3
- Quotas, constraints, and gotchas that are easy to get wrong. Assumes you already know Lambda basics (packaging, layer paths, VPC-has-no-public-IP, Graviton ≈ 34% better price-performance, Powertools APIs) — this file focuses on the values and edge cases that trip up implementations.
3
+ Specific values, limits, constraints, and code that complement general Lambda knowledge.
4
4
 
5
5
  ## Contents
6
6
 
7
7
  - [Cold Start Optimization](#cold-start-optimization)
8
+ - [Packaging](#packaging)
8
9
  - [Memory and Timeout Tuning](#memory-and-timeout-tuning)
9
10
  - [VPC Connectivity](#vpc-connectivity)
11
+ - [Execution Roles](#execution-roles)
10
12
  - [Runtime Lifecycle](#runtime-lifecycle)
11
- - [Function URLs](#function-urls)
12
- - [Powertools and Packaging](#powertools-and-packaging)
13
+ - [Powertools for AWS Lambda](#powertools-for-aws-lambda)
13
14
 
14
15
  ---
15
16
 
@@ -20,23 +21,28 @@ Quotas, constraints, and gotchas that are easy to get wrong. Assumes you already
20
21
  Snapshots the initialized execution environment (Firecracker microVM memory + disk) and restores from cache instead of cold-booting.
21
22
 
22
23
  **Supported runtimes:** Java 11+, Python 3.12+, .NET 8+
24
+ **NOT supported:** Node.js, Ruby, container images, OS-only runtimes
23
25
 
24
26
  **Constraints:**
25
27
 
26
- - **Mutually exclusive with Provisioned Concurrency** (cannot set both on one function)
28
+ - Mutually exclusive with Provisioned Concurrency
27
29
  - Mutually exclusive with Amazon EFS
28
30
  - Ephemeral storage must be ≤ 512 MB
29
31
  - Only works on published versions (not `$LATEST`)
30
- - Java: no additional SnapStart charge. Python/.NET: caching charge (by memory, min 3 hours) + per-restore charge
32
+ - Java: no additional SnapStart overhead
33
+ - Python/.NET: caching charge (based on memory, minimum 3 hours) + per-restore charge
31
34
 
32
- **Restoration gotchas** (snapshot is reused across restores):
35
+ **Restoration considerations:**
33
36
 
34
- - Generate unique IDs/secrets in the handler, not during init
37
+ - Generate unique IDs/secrets in the handler, not during init (snapshot reuse)
35
38
  - Re-establish network connections in the handler (connections are stale after restore)
36
39
  - Refresh cached timestamps/credentials in the handler
37
40
 
41
+ **CDK example (Python):**
42
+
38
43
  ```python
39
- # CDK (Python)
44
+ from aws_cdk import aws_lambda as lambda_
45
+
40
46
  fn = lambda_.Function(self, "MyFunction",
41
47
  runtime=lambda_.Runtime.PYTHON_3_13,
42
48
  handler="index.handler",
@@ -51,139 +57,492 @@ version = fn.current_version
51
57
  Pre-initializes execution environments that stay warm permanently.
52
58
 
53
59
  - A single instance handles one concurrent request at a time; throughput per instance = 1 / function duration
54
- - **Account-level RPS quota: 10 × total concurrency** (applies across all invocations, not per instance)
55
- - Supports auto-scaling via Application Auto Scaling (target ~70% utilization)
60
+ - Account-level RPS quota: 10 × total concurrency (applies across all invocations, not per instance)
61
+ - Supports auto-scaling via Application Auto Scaling
56
62
  - Lambda can scale beyond provisioned count using on-demand instances
57
63
  - **Paid even when idle** — disable in dev/staging
58
64
 
65
+ ```typescript
66
+ const fn = new lambda.Function(this, 'MyFunction', {
67
+ runtime: lambda.Runtime.NODEJS_22_X,
68
+ handler: 'index.handler',
69
+ code: lambda.Code.fromAsset('lambda'),
70
+ });
71
+
72
+ const version = fn.currentVersion;
73
+ const alias = new lambda.Alias(this, 'ProdAlias', {
74
+ aliasName: 'prod',
75
+ version,
76
+ provisionedConcurrentExecutions: 10,
77
+ });
78
+ ```
79
+
80
+ ### Graviton (arm64)
81
+
82
+ - **Up to 34% better price-performance** compared to x86 (per AWS)
83
+ - Supported for all Lambda managed runtimes
84
+ - Set `architecture: lambda_.Architecture.ARM_64` in CDK
85
+
59
86
  ### Strategy Selection
60
87
 
61
88
  | Scenario | Strategy |
62
89
  |---|---|
63
90
  | Java/Python/.NET with heavy init | SnapStart |
64
- | Strict <50ms cold start, or need EFS / >512MB ephemeral | Provisioned Concurrency |
91
+ | Strict <50ms cold start | Provisioned Concurrency |
65
92
  | Tolerant of occasional cold starts | On-demand + minimize package |
66
93
  | Predictable traffic | Provisioned Concurrency + auto-scaling |
67
94
  | General optimization | arm64 (Graviton) |
68
95
 
69
96
  ---
70
97
 
98
+ ## Packaging
99
+
100
+ ### Decision Tree
101
+
102
+ ```
103
+ Need > 250 MB uncompressed?
104
+ └─ YES → Container image (up to 10 GB)
105
+ └─ NO
106
+ ├─ Sharing deps across multiple functions?
107
+ │ └─ YES → Lambda layers
108
+ └─ NO
109
+ ├─ Simple function, few deps → .zip
110
+ └─ Native binaries, complex build → Container image
111
+ ```
112
+
113
+ ### Size Limits
114
+
115
+ | Package Type | Limit |
116
+ |---|---|
117
+ | .zip compressed | 50 MB |
118
+ | .zip uncompressed (including layers) | 250 MB |
119
+ | Container image | 10 GB |
120
+ | Layers per function | 5 |
121
+
122
+ ### Layer Paths by Runtime
123
+
124
+ | Runtime | Layer Path |
125
+ |---|---|
126
+ | Python | `python/` or `python/lib/python3.x/site-packages/` |
127
+ | Node.js | `nodejs/node_modules/` |
128
+ | Java | `java/lib/` |
129
+ | Ruby | `ruby/gems/3.4.0/` or `ruby/lib/` |
130
+ | All runtimes | `bin/` (PATH), `lib/` (LD_LIBRARY_PATH) |
131
+
132
+ **Layer constraints:**
133
+
134
+ - Layers count toward the 250 MB unzipped limit
135
+ - Layers only work with .zip deployments, NOT container images
136
+ - Not recommended for Go/Rust — bundle deps in the deployment package
137
+ - Multiple layers with conflicting dependency versions cause subtle bugs; merge order matters
138
+
139
+ ### Container Image Dockerfile
140
+
141
+ ```dockerfile
142
+ FROM public.ecr.aws/lambda/python:3.13
143
+
144
+ COPY requirements.txt .
145
+ RUN pip install -r requirements.txt
146
+
147
+ COPY app.py ${LAMBDA_TASK_ROOT}
148
+
149
+ CMD ["app.handler"]
150
+ ```
151
+
152
+ - Use official AWS base images from `public.ecr.aws/lambda/`
153
+ - Container images do NOT support Lambda layers
154
+ - SnapStart is NOT supported with container images
155
+
156
+ ### Python Build Tips
157
+
158
+ Use `uv` for dependency installation — **10-100x faster than pip**:
159
+
160
+ ```bash
161
+ uv pip install -r requirements.txt --target ./package
162
+ ```
163
+
164
+ Cross-platform build flags (when building on non-Linux):
165
+
166
+ ```bash
167
+ pip install -r requirements.txt \
168
+ --target ./package \
169
+ --platform manylinux2014_x86_64 \
170
+ --only-binary=:all:
171
+ ```
172
+
173
+ Use `manylinux2014_aarch64` for arm64. Exclude `__pycache__`, `.pyc`, tests, docs.
174
+
175
+ ---
176
+
71
177
  ## Memory and Timeout Tuning
72
178
 
73
- ### Memory → CPU
179
+ ### Memory
74
180
 
75
181
  | Parameter | Value |
76
182
  |---|---|
77
- | Range | 128 MB – 10,240 MB (1 MB increments), default 128 MB |
78
- | **1 vCPU at** | **1,769 MB** |
183
+ | Minimum | 128 MB |
184
+ | Maximum | 10,240 MB (10 GB) |
185
+ | Increment | 1 MB |
186
+ | Default | 128 MB |
187
+ | 1 vCPU at | 1,769 MB |
79
188
  | ~5.8 vCPUs at | 10,240 MB |
80
189
 
81
- CPU scales linearly with memory doubling memory doubles CPU. **Over-provisioning memory often lowers cost** (faster execution = less billed duration). Start at 256–512 MB; tune with [AWS Lambda Power Tuning](https://github.com/alexcasalboni/aws-lambda-power-tuning) against `Max Memory Used` in REPORT lines.
190
+ CPU scales linearly with memory. Doubling memory doubles CPU. **Over-provisioning memory can improve performance** faster execution = less total duration.
191
+
192
+ **Tuning process:**
82
193
 
83
- ### Ephemeral storage (/tmp)
194
+ 1. Start at 256–512 MB (128 MB only for trivial event routers)
195
+ 2. Monitor `Max Memory Used` in CloudWatch REPORT lines
196
+ 3. Use **AWS Lambda Power Tuning** (open-source Step Functions tool):
84
197
 
85
- - 512 MB (default/min) – 10,240 MB; extra cost above 512 MB
86
- - Persists across warm invocations (transient cache); NOT cleared after invoke failures
87
- - SnapStart requires ≤ 512 MB
198
+ ```bash
199
+ aws stepfunctions start-execution \
200
+ --state-machine-arn arn:aws:states:REGION:ACCOUNT:stateMachine:powerTuningStateMachine \
201
+ --input '{
202
+ "lambdaARN": "arn:aws:lambda:REGION:ACCOUNT:function:my-function",
203
+ "powerValues": [128, 256, 512, 1024, 1769, 3008],
204
+ "num": 50,
205
+ "payload": "{\"test\": true}"
206
+ }'
207
+ ```
208
+
209
+ ### Ephemeral Storage (/tmp)
210
+
211
+ | Parameter | Value |
212
+ |---|---|
213
+ | Minimum / Default | 512 MB |
214
+ | Maximum | 10,240 MB (10 GB) |
215
+ | Extra cost | Above 512 MB |
216
+
217
+ - Content **persists across warm invocations** (use as transient cache)
218
+ - Content is NOT cleared after invoke failures
219
+ - SnapStart requires ≤ 512 MB ephemeral storage
88
220
 
89
221
  ### Timeout
90
222
 
91
- - Range 1s 900s (15 min); **default is 3s** — always set it explicitly
223
+ | Parameter | Value |
224
+ |---|---|
225
+ | Minimum | 1 second |
226
+ | Maximum | 900 seconds (15 minutes) |
227
+ | Default | 3 seconds |
92
228
 
93
229
  **Critical integration limits:**
94
230
 
95
- - **API Gateway REST API: 29s default** adjustable higher for Regional/private APIs; **edge-optimized remains 29s max**
96
- - **API Gateway HTTP API: 30s hard limit** (cannot be raised)
97
- - SQS visibility timeout should be **≥ 6× function timeout**
231
+ - API Gateway REST API: **29s default** (adjustable for Regional/private APIs since June 2024; edge-optimized remains 29s max)
232
+ - API Gateway HTTP API: **30-second hard limit**
233
+ - SQS visibility timeout must be **≥ 6× function timeout** (AWS recommendation)
98
234
 
99
- ### Other limits worth knowing
235
+ ### Other Limits
100
236
 
101
237
  | Resource | Limit |
102
238
  |---|---|
239
+ | Environment variables (total) | 4 KB |
103
240
  | Sync invocation payload (request/response) | 6 MB each |
104
241
  | Async invocation payload | 1 MB |
105
- | Streamed response | 200 MB (2 MBps after first 6 MB) |
106
- | Environment variables (total) | 4 KB |
107
- | Concurrent executions (default) | 1,000 per region (soft) |
108
- | Scaling rate | 1,000 new environments / 10s, per function |
242
+ | Streamed response | 200 MB (first 6 MB uncapped, then 2 MBps) |
243
+ | File descriptors | 1,024 |
244
+ | Processes/threads | 1,024 |
245
+ | Concurrent executions (default) | 1,000 per region (soft limit) |
246
+ | Scaling rate | 1,000 new environments every 10s per function |
247
+ | Function code storage (.zip) | 75 GB per region (soft limit) |
109
248
 
110
249
  ---
111
250
 
112
251
  ## VPC Connectivity
113
252
 
114
- Lambda uses **Hyperplane ENIs** — shared across functions that use the same subnet + security group combination (NOT per-function). Each ENI supports ~65,000 connections.
253
+ ### Hyperplane ENI
254
+
255
+ Lambda uses **Hyperplane Elastic Network Interfaces** (shared, not per-function):
256
+
257
+ - Shared across functions using the same subnet + security group combination
258
+ - Each ENI supports **65,000 connections/ports**
259
+ - First-time ENI creation: **several minutes** (function stays in `Pending`)
260
+ - ENIs reclaimed after **14 days of inactivity** (function goes `Inactive`)
261
+ - Removing VPC config takes up to **20 minutes** for ENI cleanup
262
+ - Default quota: **500 Hyperplane ENIs per VPC** (Lambda-specific soft limit, can be increased). The broader VPC ENI service quota is **5,000 per region** by default.
263
+
264
+ ### Internet Access Patterns
265
+
266
+ **Lambda in a VPC NEVER gets a public IP**, even in a public subnet.
267
+
268
+ **Pattern 1: Private Subnet + NAT Gateway** (most common)
269
+
270
+ ```
271
+ Lambda → Private Subnet → Route Table → NAT Gateway → IGW → Internet
272
+ ```
273
+
274
+ - Deploy in each AZ for HA
275
+
276
+ **Pattern 2: VPC Endpoints** (for AWS services)
277
+
278
+ ```
279
+ Lambda → Private Subnet → VPC Endpoint → AWS Service
280
+ ```
281
+
282
+ - **Gateway endpoints:** S3, DynamoDB
283
+ - **Interface endpoints:** STS, Secrets Manager, SQS, etc.
284
+ - Traffic stays on AWS network — lower latency
115
285
 
116
- - First-time ENI creation can take **several minutes** (function stays `Pending`)
117
- - ENIs reclaimed after **14 days of inactivity** (function goes `Inactive`); removing VPC config takes up to **20 minutes**
286
+ #### Pattern 3: IPv6 Egress-Only Internet Gateway
118
287
 
119
- Reuse subnet + SG combos to share ENIs. Prefer **VPC endpoints** (gateway: S3, DynamoDB; interface: STS, Secrets Manager, SQS, …) over NAT Gateway for AWS-service access — lower latency, traffic stays on the AWS backbone. Don't attach to a VPC unless you need private resources (RDS, ElastiCache). VPC-attached functions need `AWSLambdaVPCAccessExecutionRole`.
288
+ ```
289
+ Lambda → Dual-Stack Subnet → Egress-Only IGW → Internet (IPv6)
290
+ ```
291
+
292
+ - Eliminates NAT Gateway for IPv6 traffic
293
+ - Requires dual-stack subnets and IPv6-capable endpoints
294
+ - Set `Ipv6AllowedForDualStack=true` in function config
295
+
296
+ ### Required IAM Permissions
297
+
298
+ VPC-attached functions need `AWSLambdaVPCAccessExecutionRole` managed policy or equivalent EC2 network interface permissions.
299
+
300
+ ### Best Practices
301
+
302
+ - Reuse subnet + security group combos across functions to share ENIs
303
+ - Use multiple subnets across AZs for HA
304
+ - Prefer VPC endpoints over NAT Gateway for AWS service access
305
+ - Don't attach to VPC unless accessing private resources (RDS, ElastiCache, etc.)
306
+
307
+ ---
308
+
309
+ ## Execution Roles
310
+
311
+ One execution role per function. Key Lambda-specific managed policies:
312
+
313
+ | Policy | Grants |
314
+ |---|---|
315
+ | `AWSLambdaBasicExecutionRole` | CloudWatch Logs only |
316
+ | `AWSLambdaVPCAccessExecutionRole` | VPC ENI management |
317
+ | `AWSLambdaDynamoDBExecutionRole` | DynamoDB Streams |
318
+ | `AWSLambdaSQSQueueExecutionRole` | SQS polling |
319
+ | `AWSLambdaKinesisExecutionRole` | Kinesis Streams |
120
320
 
121
321
  ---
122
322
 
123
323
  ## Runtime Lifecycle
124
324
 
325
+ ### Phases
326
+
125
327
  ```
126
- INIT ──▶ INVOKE (repeat) ──▶ SHUTDOWN [+ RESTORE phase for SnapStart]
328
+ ┌─────────┐ ┌─────────┐ ┌──────────┐
329
+ │ INIT │───▶│ INVOKE │───▶│ SHUTDOWN │
330
+ │ │ │(repeat) │ │ │
331
+ └─────────┘ └─────────┘ └──────────┘
127
332
  ```
128
333
 
129
- **Init phase** (extension init → runtime init → function init):
334
+ **Init Phase** (3 sub-phases: extension init → runtime init → function init):
335
+
336
+ - On-demand timeout: **10 seconds**
337
+ - Provisioned/SnapStart timeout: **up to 15 minutes**
338
+ - If init exceeds 10s on-demand, Lambda retries at first invocation using the function's configured timeout
339
+
340
+ **Invoke Phase:**
130
341
 
131
- - **On-demand init timeout: 10s.** If exceeded, Lambda retries at first invocation using the function's configured timeout.
132
- - **Provisioned/SnapStart init timeout: up to 15 minutes.**
342
+ - Limited by function timeout (max 900s)
343
+ - Each environment handles **one concurrent invocation** at a time
133
344
 
134
- **Shutdown phase:** 0 ms (no extensions), 500 ms (internal only), 2,000 ms (external extensions); SIGKILL if not done in time.
345
+ **Shutdown Phase:**
135
346
 
136
- **Restore phase (SnapStart):** 10s timeout for restore + after-restore hooks.
347
+ - 0 ms (no extensions), 500 ms (internal only), 2,000 ms (external extensions)
348
+ - SIGKILL if extensions don't respond in time
137
349
 
138
- ### Warm-start reuse
350
+ **Restore Phase** (SnapStart only):
139
351
 
140
- Objects initialized outside the handler persist across invocations (SDK clients, DB connections, `/tmp`). Gotchas:
352
+ - Resumes from cached snapshot
353
+ - 10-second timeout for restore + after-restore hooks
141
354
 
142
- - **Execution environments are recycled periodically** for maintenance even under continuous load — never assume an environment (or its warmed state) lives indefinitely.
143
- - **Global variables persist** — stale DB connections, expired credentials, and leaked state across invocations cause subtle production bugs. Refresh connections/credentials in the handler.
355
+ ### Execution Environment Reuse (Warm Starts)
356
+
357
+ Objects initialized outside the handler persist across invocations:
358
+
359
+ - SDK clients, DB connections, cached data all survive
360
+ - `/tmp` content persists (512 MB–10 GB)
361
+ - Background processes resume on next invocation
362
+ - **Workers have a maximum lease lifetime of ~14 hours** (observed behavior, not a documented SLA — do not depend on this value)
363
+ - Environments terminated periodically for maintenance even under continuous load
364
+
365
+ **Common pitfall:** Global variables persist — stale DB connections, expired credentials, and leaked state across invocations cause subtle production bugs.
366
+
367
+ ### Extensions
368
+
369
+ - **Internal:** Run in the runtime process (APM agents)
370
+ - **External:** Separate processes alongside the runtime
371
+ - Use Extensions API and Telemetry API for lifecycle events, logs, metrics, traces
144
372
 
145
373
  ---
146
374
 
147
- ## Function URLs
375
+ ## Powertools for AWS Lambda
376
+
377
+ Official AWS toolkit for Lambda best practices. Available for Python, TypeScript, Java, .NET.
378
+
379
+ **Performance note:** Powertools adds cold start overhead. Use selective imports when cold start matters:
148
380
 
149
- A Function URL is a dedicated HTTPS endpoint on a single function — no API Gateway. Use for internal service-to-service (IAM auth), Lambdalith + CloudFront, response streaming, or webhook receivers. There's **no built-in rate limiting, WAF, or request validation** (front with CloudFront/API Gateway if you need those). Choose **API Gateway** instead for public APIs needing rate limiting, JWT/Cognito auth, multi-function routing, request validation, or WAF without CloudFront.
381
+ ```python
382
+ # Instead of: from aws_lambda_powertools import Logger, Tracer, Metrics
383
+ # Import only what you need if cold start is critical
384
+ from aws_lambda_powertools import Logger
385
+ ```
150
386
 
151
- Invoking a Function URL **always requires `lambda:InvokeFunctionUrl` and `lambda:InvokeFunction`** — granting only `InvokeFunctionUrl` returns **HTTP 403** even with `AuthType=NONE`. The two `AuthType` options differ in *how* those permissions are supplied:
387
+ ### Core Utilities
152
388
 
153
- ### `AuthType=AWS_IAM` (non-public prefer for production)
389
+ | Utility | Purpose |
390
+ |---|---|
391
+ | Logger | Structured JSON logging with correlation IDs |
392
+ | Tracer | X-Ray tracing with decorators/middleware |
393
+ | Metrics | CloudWatch metrics via Embedded Metric Format (EMF) |
394
+ | Idempotency | Make handlers idempotent using DynamoDB |
395
+ | Batch Processing | Partial failure handling for SQS, Kinesis, DynamoDB Streams |
396
+ | Event Handler | Routing for API Gateway, ALB, Function URLs, AppSync |
397
+ | Parameters | Retrieve/cache SSM, Secrets Manager, AppConfig, DynamoDB values |
154
398
 
155
- Only callers with valid AWS credentials that sign requests with **SigV4** can invoke; unauthenticated requests get **403**.
399
+ ### Environment Variables
156
400
 
157
- - **Same-account caller:** grant the two actions in the caller's **identity-based policy** *or* the function's resource-based policy — a resource-based policy is **optional** if the caller's identity policy already allows them (this is why an admin/broad identity policy invokes with no resource policy on the function).
158
- - **Cross-account caller:** requires **both** an identity-based policy on the caller **and** a resource-based policy on the function.
159
- - For CloudFront in front, use **Origin Access Control** to sign requests rather than `NONE`.
401
+ | Variable | Purpose |
402
+ |---|---|
403
+ | `POWERTOOLS_SERVICE_NAME` | Service name for logs, metrics, traces |
404
+ | `POWERTOOLS_METRICS_NAMESPACE` | CloudWatch metrics namespace |
405
+ | `POWERTOOLS_LOG_LEVEL` | Logging level (DEBUG, INFO, WARNING, ERROR) |
406
+ | `POWERTOOLS_TRACE_DISABLED` | Disable tracing (useful for tests) |
407
+ | `POWERTOOLS_DEV` | Dev mode (pretty-print JSON, verbose errors) |
160
408
 
161
- ### `AuthType=NONE` (public)
409
+ ### Python: Logger + Tracer + Metrics
162
410
 
163
- Lambda does no auth — the resource-based policy alone gates access, so it must grant **public** access. Only use when the endpoint must be reachable by unauthenticated clients (e.g. a browser hitting the URL directly) with no CloudFront/edge auth in front; it exposes the function to anyone with the URL, so pair it with in-code auth, throttling, and monitoring. The console and SAM add both required statements automatically; with the CLI/API add each yourself (two separate `add-permission` calls):
411
+ ```python
412
+ from aws_lambda_powertools import Logger, Tracer, Metrics
413
+ from aws_lambda_powertools.metrics import MetricUnit
414
+ from aws_lambda_powertools.utilities.typing import LambdaContext
415
+
416
+ logger = Logger()
417
+ tracer = Tracer()
418
+ metrics = Metrics()
419
+
420
+ @logger.inject_lambda_context(log_event=False)
421
+ @tracer.capture_lambda_handler
422
+ @metrics.log_metrics(capture_cold_start_metric=True)
423
+ def handler(event: dict, context: LambdaContext) -> dict:
424
+ logger.info("Processing order", order_id=event.get("order_id"))
425
+ metrics.add_metric(name="OrdersProcessed", unit=MetricUnit.Count, value=1)
426
+ result = process_order(event)
427
+ return {"statusCode": 200, "body": result}
428
+
429
+ @tracer.capture_method
430
+ def process_order(event: dict) -> str:
431
+ return "processed"
432
+ ```
164
433
 
165
- ```bash
166
- # Statement 1: allow invoking via the Function URL (public)
167
- aws lambda add-permission --function-name my-function \
168
- --statement-id FunctionURLAllowPublicAccess \
169
- --action lambda:InvokeFunctionUrl --principal '*' \
170
- --function-url-auth-type NONE
434
+ ### TypeScript: Logger + Tracer + Metrics
435
+
436
+ ```typescript
437
+ import { Logger } from '@aws-lambda-powertools/logger';
438
+ import { Tracer } from '@aws-lambda-powertools/tracer';
439
+ import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
440
+ import middy from '@middy/core';
441
+ import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
442
+ import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
443
+ import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
444
+
445
+ const logger = new Logger({ serviceName: 'orderService' });
446
+ const tracer = new Tracer({ serviceName: 'orderService' });
447
+ const metrics = new Metrics({ namespace: 'OrderApp', serviceName: 'orderService' });
448
+
449
+ const lambdaHandler = async (event: any) => {
450
+ logger.info('Processing order', { orderId: event.orderId });
451
+ metrics.addMetric('OrdersProcessed', MetricUnit.Count, 1);
452
+ const result = await processOrder(event);
453
+ return { statusCode: 200, body: JSON.stringify(result) };
454
+ };
455
+
456
+ export const handler = middy(lambdaHandler)
457
+ .use(injectLambdaContext(logger, { logEvent: false }))
458
+ .use(captureLambdaHandler(tracer))
459
+ .use(logMetrics(metrics, { captureColdStartMetric: true }));
460
+ ```
171
461
 
172
- # Statement 2: REQUIRED — allow the underlying invoke, scoped to URL calls
173
- aws lambda add-permission --function-name my-function \
174
- --statement-id FunctionURLInvokeAllowPublicAccess \
175
- --action lambda:InvokeFunction --principal '*' \
176
- --invoked-via-function-url
462
+ ### Python: Idempotency
463
+
464
+ ```python
465
+ from aws_lambda_powertools.utilities.idempotency import (
466
+ DynamoDBPersistenceLayer,
467
+ idempotent,
468
+ )
469
+
470
+ persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
471
+
472
+ @idempotent(persistence_store=persistence_layer)
473
+ def handler(event: dict, context) -> dict:
474
+ payment = process_payment(event)
475
+ return {"payment_id": payment.id, "status": "success"}
177
476
  ```
178
477
 
179
- The `lambda:InvokedViaFunctionUrl` condition on statement 2 (set by `--invoked-via-function-url`) restricts that grant to Function URL calls, so it does not open direct `Invoke` access. See [Lambda function URL auth](https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html).
478
+ ### TypeScript: Idempotency
479
+
480
+ ```typescript
481
+ import { makeIdempotent } from '@aws-lambda-powertools/idempotency';
482
+ import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
180
483
 
181
- ## Powertools and Packaging
484
+ const persistenceStore = new DynamoDBPersistenceLayer({
485
+ tableName: 'IdempotencyTable',
486
+ });
182
487
 
183
- Use **Powertools for AWS Lambda** (Python, TypeScript, Java, .NET) for structured logging, X-Ray tracing, EMF metrics, idempotency, batch processing, event handling, and parameter caching. The APIs are well-documented at [docs.powertools.aws.dev](https://docs.powertools.aws.dev/lambda/); for a ready-to-use Python handler with Logger + Tracer + Metrics + Idempotency wired, start from [assets/powertools-handler.py](../assets/powertools-handler.py).
488
+ const processPayment = async (event: { paymentId: string; amount: number }) => {
489
+ return { paymentId: event.paymentId, status: 'success' };
490
+ };
184
491
 
185
- Powertools adds cold-start overhead use selective imports when cold start is critical.
492
+ export const handler = makeIdempotent(processPayment, {
493
+ persistenceStore,
494
+ });
495
+ ```
496
+
497
+ ### Python: Batch Processing (SQS Partial Failures)
498
+
499
+ ```python
500
+ from aws_lambda_powertools.utilities.batch import (
501
+ BatchProcessor,
502
+ EventType,
503
+ process_partial_response,
504
+ )
505
+ from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
506
+
507
+ processor = BatchProcessor(event_type=EventType.SQS)
508
+
509
+ def record_handler(record: SQSRecord):
510
+ payload = record.json_body
511
+ process_item(payload)
512
+
513
+ def handler(event, context):
514
+ return process_partial_response(
515
+ event=event,
516
+ record_handler=record_handler,
517
+ processor=processor,
518
+ context=context,
519
+ )
520
+ ```
521
+
522
+ ### TypeScript: Batch Processing (SQS Partial Failures)
523
+
524
+ ```typescript
525
+ import {
526
+ BatchProcessor,
527
+ EventType,
528
+ processPartialResponse,
529
+ } from '@aws-lambda-powertools/batch';
530
+ import type { SQSRecord, SQSHandler } from 'aws-lambda';
531
+
532
+ const processor = new BatchProcessor(EventType.SQS);
533
+
534
+ const recordHandler = async (record: SQSRecord): Promise<void> => {
535
+ const payload = JSON.parse(record.body);
536
+ await processItem(payload);
537
+ };
538
+
539
+ export const handler: SQSHandler = async (event, context) => {
540
+ return processPartialResponse(event, recordHandler, processor, {
541
+ context,
542
+ });
543
+ };
544
+ ```
186
545
 
187
- **Useful Powertools env vars:** `POWERTOOLS_SERVICE_NAME`, `POWERTOOLS_METRICS_NAMESPACE`, `POWERTOOLS_LOG_LEVEL`, `POWERTOOLS_TRACE_DISABLED` (tests), `POWERTOOLS_DEV` (pretty-print).
546
+ ### Asset Reference
188
547
 
189
- **Packaging quick facts:** 50 MB zipped / 250 MB unzipped (incl. layers) → switch to container image (10 GB) past that. Max 5 layers/function; layers don't work with container images. Use `uv pip install` (10–100× faster than pip) and `--platform manylinux2014_{x86_64,aarch64} --only-binary=:all:` for cross-platform builds, or let `sam build` handle it. See [troubleshooting.md](troubleshooting.md) for size/import errors.
548
+ For a ready-to-use Python handler with Powertools wired, read [assets/powertools-handler.py](../assets/powertools-handler.py).