sam local invokes httpapi with payload version 1.0 events despite payloadFormatVersion: 2.0 config
See original GitHub issueDescription:
aws sam local start-api
sends events in the version 1.0 payload version to lambdas configured with payloadFormatVersion: 2.0
.
Steps to reproduce:
I’ve configured an HttpApi resource that delegates to a Lambda. Both the path within the OpenAPI spec used to create the HttpApi and the backing Function are configured with payloadFormatVersion: 2.0
.
The OpenAPI spec path:
/mypath/{storeId}
parameters:
- $ref: "#/components/parameters/storeId"
get:
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
x-amazon-apigateway-integration:
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations
httpMethod: POST
passthroughBehavior: when_no_match
payloadFormatVersion: 2.0
The SAM template lambda definition:
MyFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: MyFunction
CodeUri: ./js/MyFunction/
Handler: index.handler
Runtime: nodejs10.x
Events:
GetRequest:
Type: HttpApi
Properties:
ApiId: !Ref ApiGateway
Path: /mypath/{storeId}
Method: GET
PayloadFormatVersion: 2.0
Auth:
Authorizer: NONE
Observed result:
Starting up the SAM environment locally with sam local start-api
and hitting the endpoint results in the lambda being invoked with the 1.0 version of the event payload:
2021-03-03 19:01:34,165 | Constructed String representation of Event to invoke Lambda. Event: {
"body": null,
"headers": {
"Connection": "close",
"Host": "0.0.0.0:3000",
"User-Agent": "Paw/3.2.2 (Macintosh; OS X/11.2.2) GCDHTTPRequest",
"X-Forwarded-Port": "3000",
"X-Forwarded-Proto": "http"
},
"httpMethod": "GET",
"isBase64Encoded": false,
"multiValueHeaders": {
"Connection": [
"close"
],
"Host": [
"0.0.0.0:3000"
],
"User-Agent": [
"Paw/3.2.2 (Macintosh; OS X/11.2.2) GCDHTTPRequest"
],
"X-Forwarded-Port": [
"3000"
],
"X-Forwarded-Proto": [
"http"
]
},
"multiValueQueryStringParameters": null,
"path": "/mypath/{storeId}",
"pathParameters": {
"storeId": "foo"
},
"queryStringParameters": null,
"requestContext": {
"accountId": "123456789012",
"apiId": "1234567890",
"domainName": "0.0.0.0:3000",
"extendedRequestId": null,
"httpMethod": "GET",
"identity": {
"accountId": null,
"apiKey": null,
"caller": null,
"cognitoAuthenticationProvider": null,
"cognitoAuthenticationType": null,
"cognitoIdentityPoolId": null,
"sourceIp": "172.21.0.1",
"user": null,
"userAgent": "Custom User Agent String",
"userArn": null
},
"path": "/mypath/{storeId}",
"protocol": "HTTP/1.1",
"requestId": "f6c8e16c-53fd-4122-b473-c956e76df52c",
"requestTime": "03/Mar/2021:18:15:41 +0000",
"requestTimeEpoch": 1614795341,
"resourceId": "123456",
"resourcePath": "/mypath/{storeId}",
"stage": "STAGE"
},
"resource": "/mypath/{storeId}",
"stageVariables": null,
"version": "1.0"
}
Expected result:
The payload sent to the local Lambda function should be in the 2.0 version format.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Docker/Linux/
FROM amazon/aws-cli:2.1.28
sam --version
: SAM CLI, version 1.19.1- AWS region: local
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
HttpApi - AWS Serverless Application Model
The object describing an event source with type HttpApi. ... NOTE: PayloadFormatVersion requires SAM to modify your OpenAPI definition, so it only works ......
Read more >AWS SAM - local api call to return version 2 of the event
I found the resolution in this post. It is necessary to specify PayloadFormatVersion: "2.0" (value as string) in the configuration of ...
Read more >Your Complete API Gateway and CORS Guide
To add further confusion, HTTP API isn't Version 2 of API Gateway, but there is a version 2 of the spec. Payload format...
Read more >API Gateway: Explaining Lambda Payload version 2.0 in ...
Although HTTP API provides a way to use 1.0 version of Lambda payload, changing the default introduced breaking changes from beta.
Read more >Tag Archives: http api - Noise
A Lambda authorizer is a Lambda function which API Gateway calls for an ... Select Payload format version 2.0 with a Simple response....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Updates: Verified when
PayloadFormatVersion
is not set, it will use2.0
by default. The correct usage isPayloadFormatVersion: "2.0"
. We’re currently working on a validation to make surePayloadFormatVersion
needs to be"1.0"
or"2.0"
if specified.In addition, I just observed that it sends version 1.0 of the payload when
PayloadFormatVersion
is not specified, in which case the docs say it should default to version 2.0: