Lambda Handler¶
The app module in lambda/app.py is the Powertools-based request handler
wired into API Gateway. It owns the /greeting route, Pydantic validation, and
the cross-cutting concerns (idempotency, feature flags, metrics, tracing).
API reference¶
app
¶
Serverless App Lambda handler — the handler layer.
This module initializes the AWS Powertools resolver and the AWS provider clients
(SSM, AppConfig feature flags, the DynamoDB idempotency layer) with a shared
retry config, validates the environment at cold start, routes the API Gateway
event, and translates the service layer's domain errors into HTTP responses. The
business logic lives in :mod:service and the data contracts in :mod:models,
so this file stays focused on wiring and the HTTP boundary.
It demonstrates the Powertools utilities a production handler leans on: structured logging, X-Ray tracing, CloudWatch metrics, idempotency, SSM parameters, feature flags, Pydantic-backed request/response validation (with an OpenAPI spec generated at documentation-build time — see scripts/generate_openapi.py), and Event Source Data Classes.
get_greeting()
¶
Handle GET /greeting requests.
Extracts request metadata from the typed API Gateway event, delegates the
business logic to :func:service.build_greeting, and maps a service-layer
:class:service.GreetingUnavailableError to an HTTP 500.
Returns:
| Name | Type | Description |
|---|---|---|
GreetingResponse |
GreetingResponse
|
Validated response model with a |
Source code in lambda/app.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
lambda_handler(event, context)
¶
Lambda entry point.
Resolves the API Gateway event through the router and returns the result. Decorated with Powertools Logger, Tracer, Metrics; the inner function handles Idempotency so the idempotency layer's caller-caused rejections map to meaningful HTTP responses — a missing Idempotency-Key header to a 400, a duplicate request whose original is still executing to a 409 — instead of unhandled 5xx errors. Infrastructure faults (e.g. the persistence layer's DynamoDB errors) deliberately propagate so they surface in the Errors metric and X-Ray rather than being flattened into a client-error shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict[str, Any]
|
API Gateway Lambda proxy event. |
required |
context
|
LambdaContext
|
Lambda runtime context. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
API Gateway Lambda proxy response. |