Skip to content

Conversation

@bnusunny
Copy link
Collaborator

@bnusunny bnusunny commented Jan 23, 2024

Issue #, if available:

related to awslabs/aws-lambda-web-adapter#317

Description of changes:

Add 'deny_unknown_fields' to ApiGatewayProxyRequest, ApiGatewayV2httpRequest, and ApiGatewayWebsocketProxyRequest. This prevents the runtime to deserialize Bedrock Agent event as 'ApiGatewayProxyRequest'.

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

@bnusunny bnusunny requested a review from calavera January 23, 2024 02:26
@calavera
Copy link
Contributor

We just removed those attributes in #753. Can we do anything else to improve the serialization logic besides that?

@bnusunny
Copy link
Collaborator Author

The schema for these HTTP related events rarely change. For breaking changes, the service team usually publishes another version of the schema. For example, APIGW v1 and v2.

@calavera
Copy link
Contributor

Why are bedrock events being mistaken with APIGW events? they are two completely different services. I'd prefer to fix that.

@bnusunny
Copy link
Collaborator Author

Yes, they are two completely different services and schema. But 'ApiGatewayProxyRequest''s properties are either optional or have defaults. 'ApiGatewayWebsocketProxyRequest' has the same problem.

'ApiGatewayV2httpRequest' has 'skip_serializing_if' on several properties. 'AlbTargetGroupRequest' has one mandatory property 'http_method'.

One solution is to use 'skip_serializing_if' on 'ApiGatewayProxyRequest' and 'ApiGatewayWebsocketProxyRequest'.

@bnusunny
Copy link
Collaborator Author

I'm puzzled: the SQS event has no issue. Only Bedrock one has this issue.

@bnusunny
Copy link
Collaborator Author

I found the reason. Bedrock event has 'httpMethod'. This single property made it deserializable into 'ApiGatewayProxyRequest' and 'ApiGatewayWebsocketProxyRequest'.

…'ApiGatewayProxyRequest' and 'ApiGatewayWebsocketProxyRequest'
@bnusunny
Copy link
Collaborator Author

@calavera I have updated the PR. Please take a look again.

Copy link
Contributor

@calavera calavera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bnusunny bnusunny merged commit fde1d37 into main Jan 23, 2024
@bnusunny bnusunny deleted the tighten-lambda-http-deserializer branch January 23, 2024 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants