Unable to POST json to lambda via start-api
Description
When trying to invoke a lambda via curl POST the event data is not coming through to the lambda. If I invoke using sam cli invoke and passing the json this works fine, but using the same payload as a curl request when using sam cli start-api this payload is not getting through the lambda.
Steps to reproduce
lambda code:
type Event struct {
Field string `json:"field"`
}
func main() {
lambda.Start(handler)
}
func handler(_ context.Context, input Event) (interface{}, error) {
fmt.Print(input)
}
template:
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Runtime: go1.x
Resources:
nannyDynamodbTransaction:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/lambdas/nanny_dynamodb_transaction/
Handler: nanny_dynamodb_transaction
Runtime: go1.x
Events:
Transaction:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /transaction
Method: POST
post request:
curl -X POST -H "Content-Type: application/json" -d '{"field": "test"}' https://localhost:3000/transaction
Provide steps to replicate.
Observed result
result is {} as if the struct is never populated from the post event.
Please provide command output with --debug flag set.
Expected result
I expect the payload to be printed out
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: OS X
sam --version: 0.52.0
Hi, I tried to reproduced this issue, but the given lambda function code seems to be incomplete or wrong. I get errors like
Error: GoModulesBuilder:Build - Builder Failed: # hello-world
./main.go:12:16: undefined: context
./main.go:14:9: undefined: events
I am not familiar with go much, but can you update your lambda code or exact steps you used to help me reproduce the errors.
Also since this is old if you try in latest sam-cli and it is fixed do let me know.
Closing as this issue is inactive. Feel free to leave more information below and I can reopen this issue.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.