-
Notifications
You must be signed in to change notification settings - Fork 407
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
feat(parser): Support for API GW v1 proxy schema & envelope #403
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #403 +/- ##
===========================================
- Coverage 99.94% 99.89% -0.06%
===========================================
Files 98 100 +2
Lines 3688 3780 +92
Branches 174 175 +1
===========================================
+ Hits 3686 3776 +90
- Misses 0 1 +1
- Partials 2 3 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you @risenberg-cyberark. A few minor questions on the additional checks, and an explicit comment to tag whether this is REST API (v1) or HTTP API (v2), or both, so it's easier to add and use HTTP API later judging by the import, naming, etc.
return values | ||
|
||
@root_validator(pre=True) | ||
def check_both_http_methods(cls, values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a note why this check is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would you like to write here? basically what i saw that in the v1 version there's a duplication 3 fields, so i made sure that all values are actually the same. V2 removes this duplication
return values | ||
|
||
@root_validator(pre=True) | ||
def check_both_paths(cls, values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a note why this check is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would you like to write here? basically what i saw that in the v1 version there's a duplication 3 fields, so i made sure that all values are actually the same. V2 removes this duplication
body: str | ||
|
||
@root_validator() | ||
def check_message_id(cls, values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a note why this check is needed? e.g. spoofing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would you like to write here? basically what i saw that in the v1 version there's a duplication 3 fields, so i made sure that all values are actually the same. V2 removes this duplication
@@ -161,6 +161,7 @@ Parser comes with the following built-in models: | |||
| **KinesisDataStreamModel** | Lambda Event Source payload for Amazon Kinesis Data Streams | | |||
| **SesModel** | Lambda Event Source payload for Amazon Simple Email Service | | |||
| **SnsModel** | Lambda Event Source payload for Amazon Simple Notification Service | | |||
| **APIGatewayProxyEvent** | Lambda Event Source payload for Amazon API Gateway | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API Gateway v1, v2, or both? e.g. REST vs HTTP API. By my first look I'd guess REST API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V1
| **KinesisDataStreamEnvelope** | 1. Parses data using `KinesisDataStreamModel` which will base64 decode it. <br/> 2. Parses records in in `Records` key using your model and returns them in a list. | `List[Model]` | | ||
| **SnsEnvelope** | 1. Parses data using `SnsModel`. <br/> 2. Parses records in `body` key using your model and return them in a list. | `List[Model]` | | ||
| **SnsSqsEnvelope** | 1. Parses data using `SqsModel`. <br/> 2. Parses SNS records in `body` key using `SnsNotificationModel`. <br/> 3. Parses data in `Message` key using your model and return them in a list. | `List[Model]` | | ||
| **ApiGatewayEnvelope** 1. Parses data using `APIGatewayProxyEventModel`. <br/> 2. Parses `body` key using your model and returns it. | `Model` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API Gateway v1, v2, or both? e.g. REST vs HTTP API. By my first look I'd guess REST API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V1
Co-authored-by: Heitor Lessa <heitor.lessa@hotmail.com>
Thanks for the clarifications @risenberg-cyberark - I'm happy to merge after we remove those root validators. I don't see a need a benefit in keeping them if we, the provider, are the ones duplicating these possibly for backward compatible reasons (until HTTP API when they're gone). Alternatively, I can merge and fiz that later too - up to you. Thanks a lot for adding this support! |
@heitorlessa You remove them but I do think they add a value because if there's a discrepancy in between them, you should not use the entire payload at all , |
That's what I understood too @risenberg-cyberark ;) Putting in another way, I wouldn't like to break customers applications because this behaviour isn't documented. For this reason, I don't trust that API Gateway Lambda integration to follow through these checks consistently. |
np, removed the relevant root validator. is the last root validator ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good on the validators except I think there's an accidental duplicates field (eventType).
Mind checking before I merge?
connectedAt: Optional[datetime] | ||
connectionId: Optional[str] | ||
eventType: Optional[Literal["CONNECT", "MESSAGE", "DISCONNECT"]] | ||
eventType: Optional[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this perhaps a typo as it's defined twice?
That's for WebSockets and the line 65 is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a bad copy paste :)
removed
I bet :D Glad I checked w/ you before merging :) Merging now!
…On Wed, 21 Apr 2021 at 18:41, Ran Isenberg ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In aws_lambda_powertools/utilities/parser/models/apigw.py
<#403 (comment)>
:
> + protocol: str
+ identity: APIGatewayEventIdentity
+ requestId: str
+ requestTime: str
+ requestTimeEpoch: datetime
+ resourceId: Optional[str]
+ resourcePath: str
+ domainName: Optional[str]
+ domainPrefix: Optional[str]
+ extendedRequestId: Optional[str]
+ httpMethod: Literal["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
+ path: str
+ connectedAt: Optional[datetime]
+ connectionId: Optional[str]
+ eventType: Optional[Literal["CONNECT", "MESSAGE", "DISCONNECT"]]
+ eventType: Optional[str]
seems like a bad copy paste :)
removed
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#403 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBHENA66LKXNJP3EKZLTJ354JANCNFSM43EEWPWA>
.
|
…tools-python into fix/docs-latest-api-ref * 'develop' of https://github.com/awslabs/aws-lambda-powertools-python: feat(parser): Support for API GW v1 proxy schema & envelope (#403) fix(validator): event type annotation as any in validate fn (#405) docs(tracer): Fix line highlighting (#395) fix(workflow): github actions depends on for release chore: bump to 1.14.0 docs(logger): add example on how to set UTC timestamp (#392) docs(idempotency): add default configuration for those not using CFN (#391)
This schema exists in the validator but not in the parser. It was requested in the webinar audience.
This feature will also provide an envelope class which will parse the string body parameter as a pydantic Model.
Also added new identity parameters as defined at https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html