Skip to content

refactor(parser): Improve ALB models with examples and descriptions #7100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions aws_lambda_powertools/utilities/parser/models/alb.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
from typing import Dict, Type, Union

from pydantic import BaseModel
from pydantic import BaseModel, Field


class AlbRequestContextData(BaseModel):
targetGroupArn: str
targetGroupArn: str = Field(
description="The ARN of the target group that the request was routed to.",
examples=[
"arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/73e2d6bc24d8a067",
"arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/api-targets/1234567890123456",
],
)


class AlbRequestContext(BaseModel):
elb: AlbRequestContextData
elb: AlbRequestContextData = Field(
description="Information about the Elastic Load Balancer that processed the request.",
)


class AlbModel(BaseModel):
httpMethod: str
path: str
body: Union[str, Type[BaseModel]]
isBase64Encoded: bool
headers: Dict[str, str]
queryStringParameters: Dict[str, str]
requestContext: AlbRequestContext
httpMethod: str = Field(
description="The HTTP method used for the request.",
examples=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT"],
)
path: str = Field(
description="The path portion of the request URL.",
examples=["/", "/api/users", "/health", "/api/v1/products/123"],
)
body: Union[str, Type[BaseModel]] = Field(
description="The request body. Can be a string or a parsed model if content-type allows parsing.",
)
isBase64Encoded: bool = Field(description="Indicates whether the body is base64-encoded.", examples=[False, True])
headers: Dict[str, str] = Field(
description="The request headers as key-value pairs.",
examples=[
{"host": "example.com", "user-agent": "Mozilla/5.0"},
{"content-type": "application/json", "authorization": "Bearer token123"},
],
)
queryStringParameters: Dict[str, str] = Field(
description="The query string parameters as key-value pairs.",
examples=[{"page": "1", "limit": "10"}, {"filter": "active", "sort": "name"}],
)
requestContext: AlbRequestContext = Field(
description="Contains information about the request context, including the load balancer details.",
)