You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in the process of developing my first couple Lambda functions and doing various testing locally and after deploying to Prod.
I've been having trouble interacting with my functions locally or in Prod using HTTP. All the documentationpoints to being able to interact with your function using HTTP.
After running $ sam local start-api I am presented with (which mentions you can invoke it locally):
2019-01-16 12:21:09 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-16 12:21:09 Mounting ComponentLabeling at http://127.0.0.1:3000/component-labeling [POST]
2019-01-16 12:21:09 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2019-01-16 12:21:09 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
When invoking the endpoint using the payload as described by the documentation:
When I invoke my function using sam local invoke, everything works as expected:
echo'{ "image_url": "http://sitegif-development.s3.amazonaws.com/4f01e5e97d7d0aba4ee6959ea521e5c3/78d48838-f669-4563-a866-45639211d78c-633ea5d6-b662-4e62-956a-2cdcfe3b8030-comparison.png"}'| sam local invoke "ComponentLabeling"
2019-01-16 12:25:45 Reading invoke payload from stdin (you can also pass it from file with --event)
2019-01-16 12:25:45 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-16 12:25:45 Invoking component-labeling (go1.x)
Fetching lambci/lambda:go1.x Docker container image......
2019-01-16 12:25:46 Mounting /Users/dewski/go/src/github.com/dewski/pngdiff/component-labeling as /var/task:ro inside runtime container
{"regions":[{
(output truncated for brevity)
Really puzzled, I did some digging and noticed the handler function will be invoked with two different payloads depending on how the request was triggered (HTTP or sam):
sam local start-api mimics the api gateway proxy integration, which is what produces the envelope json you observed. When using Lambda with api gateway, sam local start-api is the right way to test locally. Also when using api gateway, the function should accept events.APIGatewayProxyRequest and return events.APIGatewayProxyResponse (example)
I'm in the process of developing my first couple Lambda functions and doing various testing locally and after deploying to Prod.
I've been having trouble interacting with my functions locally or in Prod using HTTP. All the documentation points to being able to interact with your function using HTTP.
After running
$ sam local start-api
I am presented with (which mentions you can invoke it locally):When invoking the endpoint using the payload as described by the documentation:
I am presented with:
My go application looks like this:
It matches the same handler signature as outlined in the documentation and in lambda/entry.go:
aws-lambda-go/lambda/entry.go
Line 31 in deb5700
When I invoke my function using
sam local invoke
, everything works as expected:(output truncated for brevity)
Really puzzled, I did some digging and noticed the handler function will be invoked with two different payloads depending on how the request was triggered (HTTP or sam):
aws-lambda-go/lambda/function.go
Lines 59 to 65 in deb5700
When I log the output of
req.Payload
using HTTP I get:When invoking the function using sam the payload is the expected payload:
Is this a bug or expected behavior? If it's expected behavior, how does one successfully invoke a function using HTTP?
The text was updated successfully, but these errors were encountered: