-
Notifications
You must be signed in to change notification settings - Fork 432
feat(event_handler): add support to VPC Lattice payload v2 #3153
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
leandrodamascena
merged 32 commits into
aws-powertools:develop
from
stephenbawks:vpcLatticeV2
Oct 5, 2023
Merged
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
1cf5073
updated vpc lattice v2 event
stephenbawks 7530760
updating base
stephenbawks 93cd96e
remove line break
stephenbawks b1f9e96
more details return type for request context
stephenbawks c1dbf1b
couple doc string updates
stephenbawks 680c9be
copy pasta
stephenbawks 7f25990
Merge branch 'develop' into vpcLatticeV2
leandrodamascena 3d996ac
ruff work
stephenbawks d278441
Merge branch 'develop' into vpcLatticeV2
leandrodamascena 0c48df9
small tweak
stephenbawks 27e3761
adding model 2 tests
stephenbawks 86a7ff5
starting docs
stephenbawks 687f45e
couple more tests
stephenbawks 5e47060
words matter
stephenbawks 32463a1
missing line break
stephenbawks 77ee153
ruff do work
stephenbawks 2dc9b0d
Adding more fields in parser
leandrodamascena fb07a96
pull and add examples
stephenbawks 47c12d4
where did you go
stephenbawks 54f9363
Adding more fields in parser and event source
leandrodamascena d9c702b
Convert microsecond to milisecond - need to review
leandrodamascena 54d6a2f
additional tests
stephenbawks 0c5cf99
fix path
stephenbawks 2b50d13
Wording
leandrodamascena 46c0009
Adding VPC Lattice v2 resolver
leandrodamascena 157556f
Fixing resolver
leandrodamascena 5c56a43
Fixing mypy
leandrodamascena 072987e
Merge branch 'develop' into vpcLatticeV2
leandrodamascena 144df4b
Event Handler documentation
leandrodamascena ce1f307
Preserving timeEpoch field + adding a new one
leandrodamascena 8bd48c1
Merge branch 'develop' into vpcLatticeV2
leandrodamascena f9a3ed0
Merge branch 'develop' into vpcLatticeV2
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
aws_lambda_powertools/utilities/parser/envelopes/vpc_latticev2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
from typing import Any, Dict, Optional, Type, Union | ||
|
||
from ..models import VpcLatticeV2Model | ||
from ..types import Model | ||
from .base import BaseEnvelope | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class VpcLatticeV2Envelope(BaseEnvelope): | ||
"""Amazon VPC Lattice envelope to extract data within body key""" | ||
|
||
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> Optional[Model]: | ||
"""Parses data found with model provided | ||
|
||
Parameters | ||
---------- | ||
data : Dict | ||
Lambda event to be parsed | ||
model : Type[Model] | ||
Data model provided to parse after extracting data using envelope | ||
|
||
Returns | ||
------- | ||
Optional[Model] | ||
Parsed detail payload with model provided | ||
""" | ||
logger.debug(f"Parsing incoming data with VPC Lattice V2 model {VpcLatticeV2Model}") | ||
parsed_envelope: VpcLatticeV2Model = VpcLatticeV2Model.parse_obj(data) | ||
logger.debug(f"Parsing event payload in `detail` with {model}") | ||
return self._parse(data=parsed_envelope.body, model=model) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
aws_lambda_powertools/utilities/parser/models/vpc_latticev2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from datetime import datetime | ||
from typing import Dict, Optional, Type, Union | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class VpcLatticeV2RequestContextIdentity(BaseModel): | ||
source_vpc_arn: Optional[str] = Field(None, alias="sourceVpcArn") | ||
get_type: Optional[str] = Field(None, alias="type") | ||
principal: Optional[str] = Field(None, alias="principal") | ||
principal_org_id: Optional[str] = Field(None, alias="principalOrgID") | ||
session_name: Optional[str] = Field(None, alias="sessionName") | ||
x509_subject_cn: Optional[str] = Field(None, alias="X509SubjectCn") | ||
x509_issuer_ou: Optional[str] = Field(None, alias="X509IssuerOu") | ||
x509_san_dns: Optional[str] = Field(None, alias="x509SanDns") | ||
x509_san_uri: Optional[str] = Field(None, alias="X509SanUri") | ||
x509_san_name_cn: Optional[str] = Field(None, alias="X509SanNameCn") | ||
|
||
|
||
class VpcLatticeV2RequestContext(BaseModel): | ||
service_network_arn: str = Field(alias="serviceNetworkArn") | ||
service_arn: str = Field(alias="serviceArn") | ||
target_group_arn: str = Field(alias="targetGroupArn") | ||
identity: VpcLatticeV2RequestContextIdentity | ||
region: str | ||
time_epoch: datetime = Field(alias="timeEpoch") | ||
|
||
|
||
class VpcLatticeV2Model(BaseModel): | ||
version: str | ||
path: str | ||
method: str | ||
headers: Dict[str, str] | ||
query_string_parameters: Optional[Dict[str, str]] = None | ||
body: Optional[Union[str, Type[BaseModel]]] = None | ||
stephenbawks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
is_base64_encoded: Optional[bool] = Field(None, alias="isBase64Encoded") | ||
stephenbawks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
request_context: VpcLatticeV2RequestContext = Field(None, alias="requestContext") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from aws_lambda_powertools import Logger | ||
from aws_lambda_powertools.utilities.data_classes import VPCLatticeEventV2, event_source | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
logger = Logger() | ||
|
||
|
||
@event_source(data_class=VPCLatticeEventV2) | ||
def lambda_handler(event: VPCLatticeEventV2, context: LambdaContext): | ||
logger.info(event.body) | ||
|
||
response = { | ||
"isBase64Encoded": False, | ||
"statusCode": 200, | ||
"statusDescription": "200 OK", | ||
"headers": {"Content-Type": "application/text"}, | ||
"body": "VPC Lattice V2 Event ✨🎉✨", | ||
} | ||
|
||
return response |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.