I am creating an API using AWS API Gateway with integration to AWS Lambda using Java.
I came across 3 types of Java objects that can be used as a return type in the Lambda functions.
APIGatewayV2HTTPEvent
APIGatewayProxyRequestEvent
APIGatewayV2ProxyRequestEvent
(Deprecated)I have tried creating a REST API Gateway and returned all 3 objects, the API still works.
What are the differences and which one should I be using?
There are two different types of Amazon API Gateway, REST and HTTP APIs.
The original REST type has a single payload format. For this you should use APIGatewayProxyRequestEvent.
HTTP APIs have two payload formats v1 and v2. If you're using v1 you should use APIGatewayProxyRequestEvent, and if you're using v2 you should use APIGatewayV2HTTPEvent.
From the documentation
Format 2.0 doesn't have multiValueHeaders or multiValueQueryStringParameters fields. Duplicate headers are combined with commas and included in the headers field. Duplicate query strings are combined with commas and included in the queryStringParameters field.
Format 2.0 includes a new cookies field. All cookie headers in the request are combined with commas and added to the cookies field. In the response to the client, each cookie becomes a set-cookie header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With