Skip to content

Commit dc99c10

Browse files
committed
refactor(parser): Improve VPC Lattice with examples and descriptions
1 parent 53cdbf3 commit dc99c10

File tree

2 files changed

+150
-32
lines changed

2 files changed

+150
-32
lines changed
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
from typing import Dict, Type, Union
22

3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
44

55

66
class VpcLatticeModel(BaseModel):
7-
method: str
8-
raw_path: str
9-
body: Union[str, Type[BaseModel]]
10-
is_base64_encoded: bool
11-
headers: Dict[str, str]
12-
query_string_parameters: Dict[str, str]
7+
method: str = Field(
8+
description="The HTTP method used for the request.",
9+
examples=["GET", "POST", "PUT", "DELETE", "PATCH"],
10+
)
11+
raw_path: str = Field(
12+
description="The raw path portion of the request URL.",
13+
examples=["/testpath", "/api/v1/users", "/health"],
14+
)
15+
body: Union[str, Type[BaseModel]] = Field(
16+
description="The request body. Can be a string or a parsed model if content-type allows parsing.",
17+
)
18+
is_base64_encoded: bool = Field(description="Indicates whether the body is base64-encoded.", examples=[True, False])
19+
headers: Dict[str, str] = Field(
20+
description="The request headers as key-value pairs.",
21+
examples=[
22+
{"host": "test-lambda-service.vpc-lattice-svcs.us-east-2.on.aws", "user-agent": "curl/7.64.1"},
23+
{"content-type": "application/json", "x-forwarded-for": "10.213.229.10"},
24+
],
25+
)
26+
query_string_parameters: Dict[str, str] = Field(
27+
description="The query string parameters as key-value pairs.",
28+
examples=[{"order-id": "1"}, {"page": "2", "limit": "10"}],
29+
)

aws_lambda_powertools/utilities/parser/models/vpc_latticev2.py

Lines changed: 126 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,139 @@
55

66

77
class VpcLatticeV2RequestContextIdentity(BaseModel):
8-
source_vpc_arn: Optional[str] = Field(None, alias="sourceVpcArn")
9-
get_type: Optional[str] = Field(None, alias="type")
10-
principal: Optional[str] = Field(None, alias="principal")
11-
principal_org_id: Optional[str] = Field(None, alias="principalOrgID")
12-
session_name: Optional[str] = Field(None, alias="sessionName")
13-
x509_subject_cn: Optional[str] = Field(None, alias="X509SubjectCn")
14-
x509_issuer_ou: Optional[str] = Field(None, alias="X509IssuerOu")
15-
x509_san_dns: Optional[str] = Field(None, alias="x509SanDns")
16-
x509_san_uri: Optional[str] = Field(None, alias="X509SanUri")
17-
x509_san_name_cn: Optional[str] = Field(None, alias="X509SanNameCn")
8+
source_vpc_arn: Optional[str] = Field(
9+
None,
10+
alias="sourceVpcArn",
11+
description="The ARN of the VPC from which the request originated.",
12+
examples=["arn:aws:ec2:us-east-2:123456789012:vpc/vpc-0b8276c84697e7339"],
13+
)
14+
get_type: Optional[str] = Field(
15+
None,
16+
alias="type",
17+
description="The type of identity making the request.",
18+
examples=["AWS_IAM", "NONE"],
19+
)
20+
principal: Optional[str] = Field(
21+
None,
22+
alias="principal",
23+
description="The principal ARN of the identity making the request.",
24+
examples=["arn:aws:sts::123456789012:assumed-role/example-role/057d00f8b51257ba3c853a0f248943cf"],
25+
)
26+
principal_org_id: Optional[str] = Field(
27+
None,
28+
alias="principalOrgID",
29+
description="The AWS organization ID of the principal.",
30+
examples=["o-1234567890"],
31+
)
32+
session_name: Optional[str] = Field(
33+
None,
34+
alias="sessionName",
35+
description="The session name for assumed role sessions.",
36+
examples=["057d00f8b51257ba3c853a0f248943cf"],
37+
)
38+
x509_subject_cn: Optional[str] = Field(
39+
None,
40+
alias="X509SubjectCn",
41+
description="The X.509 certificate subject common name.",
42+
examples=["example.com"],
43+
)
44+
x509_issuer_ou: Optional[str] = Field(
45+
None,
46+
alias="X509IssuerOu",
47+
description="The X.509 certificate issuer organizational unit.",
48+
examples=["IT Department"],
49+
)
50+
x509_san_dns: Optional[str] = Field(
51+
None,
52+
alias="x509SanDns",
53+
description="The X.509 certificate Subject Alternative Name DNS entry.",
54+
examples=["example.com"],
55+
)
56+
x509_san_uri: Optional[str] = Field(
57+
None,
58+
alias="X509SanUri",
59+
description="The X.509 certificate Subject Alternative Name URI entry.",
60+
examples=["https://example.com"],
61+
)
62+
x509_san_name_cn: Optional[str] = Field(
63+
None,
64+
alias="X509SanNameCn",
65+
description="The X.509 certificate Subject Alternative Name common name.",
66+
examples=["example.com"],
67+
)
1868

1969

2070
class VpcLatticeV2RequestContext(BaseModel):
21-
service_network_arn: str = Field(alias="serviceNetworkArn")
22-
service_arn: str = Field(alias="serviceArn")
23-
target_group_arn: str = Field(alias="targetGroupArn")
24-
identity: VpcLatticeV2RequestContextIdentity
25-
region: str
26-
time_epoch: float = Field(alias="timeEpoch")
27-
time_epoch_as_datetime: datetime = Field(alias="timeEpoch")
71+
service_network_arn: str = Field(
72+
alias="serviceNetworkArn",
73+
description="The ARN of the VPC Lattice service network.",
74+
examples=["arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-0bf3f2882e9cc805a"],
75+
)
76+
service_arn: str = Field(
77+
alias="serviceArn",
78+
description="The ARN of the VPC Lattice service that processed the request.",
79+
examples=["arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0a40eebed65f8d69c"],
80+
)
81+
target_group_arn: str = Field(
82+
alias="targetGroupArn",
83+
description="The ARN of the target group that received the request.",
84+
examples=["arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-6d0ecf831eec9f09"],
85+
)
86+
identity: VpcLatticeV2RequestContextIdentity = Field(description="Identity information about the requester.")
87+
region: str = Field(
88+
description="The AWS region where the request was processed.",
89+
examples=["us-east-2", "us-west-1", "eu-west-1"],
90+
)
91+
time_epoch: float = Field(
92+
alias="timeEpoch",
93+
description="The request timestamp in epoch microseconds.",
94+
examples=[1696331543569073],
95+
)
96+
time_epoch_as_datetime: datetime = Field(
97+
alias="timeEpoch",
98+
description="The request timestamp converted to datetime.",
99+
)
28100

29101
@field_validator("time_epoch_as_datetime", mode="before")
30102
def time_epoch_convert_to_miliseconds(cls, value: int):
31103
return round(int(value) / 1000)
32104

33105

34106
class VpcLatticeV2Model(BaseModel):
35-
version: str
36-
path: str
37-
method: str
38-
headers: Dict[str, str]
39-
query_string_parameters: Optional[Dict[str, str]] = Field(None, alias="queryStringParameters")
40-
body: Optional[Union[str, Type[BaseModel]]] = None
41-
is_base64_encoded: Optional[bool] = Field(None, alias="isBase64Encoded")
42-
request_context: VpcLatticeV2RequestContext = Field(..., alias="requestContext")
107+
version: str = Field(description="The version of the VPC Lattice event format.", examples=["2.0"])
108+
path: str = Field(
109+
description="The path portion of the request URL.",
110+
examples=["/newpath", "/api/v1/users", "/health"],
111+
)
112+
method: str = Field(
113+
description="The HTTP method used for the request.",
114+
examples=["GET", "POST", "PUT", "DELETE", "PATCH"],
115+
)
116+
headers: Dict[str, str] = Field(
117+
description="The request headers as key-value pairs.",
118+
examples=[
119+
{"host": "test-lambda-service.vpc-lattice-svcs.us-east-2.on.aws", "user-agent": "curl/7.64.1"},
120+
{"content-type": "application/json", "x-forwarded-for": "10.213.229.10"},
121+
],
122+
)
123+
query_string_parameters: Optional[Dict[str, str]] = Field(
124+
None,
125+
alias="queryStringParameters",
126+
description="The query string parameters as key-value pairs.",
127+
examples=[{"order-id": "1"}, {"page": "2", "limit": "10"}],
128+
)
129+
body: Optional[Union[str, Type[BaseModel]]] = Field(
130+
None,
131+
description="The request body. Can be a string or a parsed model if content-type allows parsing.",
132+
)
133+
is_base64_encoded: Optional[bool] = Field(
134+
None,
135+
alias="isBase64Encoded",
136+
description="Indicates whether the body is base64-encoded.",
137+
examples=[False, True],
138+
)
139+
request_context: VpcLatticeV2RequestContext = Field(
140+
...,
141+
alias="requestContext",
142+
description="Contains information about the request context, including VPC Lattice service details.",
143+
)

0 commit comments

Comments
 (0)