502 BAD GATEWAY for file upload through SAM with local API Gateway
See original GitHub issueDescription
When attempting to upload a photo to a local Lambda running using sam local start-api --debug
, it fails with a 502 BAD GATEWAY. No code within the Lambda is executed.
Steps to reproduce
I used curl to do the upload.
curl -v -X POST 'http://localhost:3000/v1/photo-gallery' -F 'uploadedFile=@IMG_5071.JPG
This Lambda uses Flask to handle multiple endpoints and the others are working as expected.
Observed result
Please provide command output with --debug
flag set.
SAM does not display any debug output. It just logs the request with the response set as a 502.
Expected result
I would expect that the lambda would be executed.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Mac
sam --version
: SAM CLI, version 0.17.0
Add --debug flag to command you are running
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:25 (2 by maintainers)
Top Results From Across the Web
Getting '502 BAD Gateway' while uploading image using SAM ...
When uploading a image to a SAM local Lambda function,then it fails with a 502 BAD GATEWAY. Getting 502 error before calling Lambda...
Read more >How do I resolve HTTP 502 errors from API Gateway REST ...
For API Gateway to handle a Lambda function's response, the function must return output according to the following JSON format:
Read more >502 BAD GATEWAY for file upload through SAM with local API ...
When attempting to upload a photo to a local Lambda running using sam local start-api --debug , it fails with a 502 BAD...
Read more >Serverless: AWS HTTP Gateway — 502 Bad Gateway - DZone
This quick tip for serverless functions using AWS Lambda will help conquer 502 errors. Make sure you return maps instead of strings when ......
Read more >502 Bad Gateway Error: What It Is and How to Fix It
If you're using such an application and a 502 Bad Gateway Error occurs, the issue will not be related to the app installation...
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
/
need to be written as~1
as per the documentation. After playing around I finally got the following to work. Keep in mind that this allows all binary media types.same issue here when uploading a
.txt
file it’s working fine but I’m trying a.zip
file which throw an 502 BAD GATEWAY error. API Gateway binary type set isWork around
As mentioned by pyrabbit, set the BinaryMediaTypes to
['*~1*']
In the documentation AWS says "Use
~1
instead of/
in the mime types. " but"application~1zip"
doesn’t work, maybe the documentation should add more examples of how to use the BinaryMediaTypes with working examplesAlso on the doc AWS says “This property is similar to the BinaryMediaTypes property of an AWS::ApiGateway::RestApi resource.” which uses the
/
maybe a change on the SAM CLI to support the/
should be good as we keep the same behaviors and consistency