-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Internal server error when request method OPTIONS #58
Comments
|
OPTIONS works just fine for me from postman. Couple potential reasons for "Internal server error":
|
everything is ok, only way to stop {"message": "Internal server error"} is remove options from simple-proxy-api |
Any way to resolve it? I've tried setting up |
I'll verify this later. For now, simply remove the OPTIONS method and redeploy your API and let Express deal with CORS. |
With the help from staff on AWS forums, I've resolved it by adding:
which now returns a correct 200 response for the OPTIONS request. It wasn't obvious we needed to do that however, especially that this option is not available for Mock requests through the Console yet. |
cloud you please tell us wehere to add this configuration exactly ? thanks ! |
@samikarak that needs to be added to the configuration of your OPTIONS methods in the Swagger template (https://github.com/awslabs/aws-serverless-express/blob/master/example/simple-proxy-api.yaml#L43) |
Hope this helps... In my case i had two functions with similar names: 'user-get-all' and 'user-get', defined in that order in the serverless.yml file. The error message i was getting was "Internal Server Error" + "Execution failed due to configuration error: Invalid permissions on lambda function. Method completed with status 500". After changing the name of the secon function to "user-get-item" it was solved. (Perhaps changing the order of the functions in the serverless.yml might work too). Regards, George |
If you're not using swagger, which I wasn't, a couple things solved the issue for me. First was enabling CORS in the serverless.yml functions:
api:
handler: lambda.handler
events:
- http:
path: /
method: ANY
cors: true
- http:
path: /{proxy+}
method: ANY
cors: true The second was making sure my Express setup allowed the OPTIONS method through: app.use( (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
next();
}) Hope this helps some people out. It took me a bit to figure out all the pieces. |
@dinvlad Why hasn't the file you link to just been updated with the necessary fixes? Seems like this would save people a lot of headaches- |
@chriszrc I'm not in charge of this package, sorry |
Lol, yes I know, sorry, maybe that didn't sound right. I was trying to ask
more in general, like why hasn't this example been updated by the aws folks-
…On Tue, May 8, 2018 at 10:14 AM, Denis Loginov ***@***.***> wrote:
@chriszrc <https://github.com/chriszrc> I'm not in charge of this
package, sorry
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYgWKTF928KJJCRkPk_nj0D-2mMe38G1ks5twagtgaJpZM4M7WLU>
.
--
--
Chris Marx
ZevRoss - Know Your Data
Data Science & Spatial Analysis
New website: www.zevross.com
Ithaca, NY
|
@dinvlad Do u happen to know if this can be done via API gateway console? I removed binary type * / * and OPTIONS method works using Postman. However, my audio/mp3 type doesn't work if I don't set binary type as * / * |
@Jun711 haven't worked with SAM in a while, we've migrated to Firebase, sorry |
Reopening this to track fixing the example https://github.com/awslabs/aws-serverless-express/blob/master/example/simple-proxy-api.yaml#L43. Easy first PR for someone :) |
@brettstack |
Okay I'll leave this open until I can confirm. Alternative is to simply remove the OPTIONS method from the Swagger template and let Lamdba handle the preflight request. Having the OPTIONS method is a performance enhancement (i.e. the response will be faster since it's terminated at the API Gateway layer) |
It can also be a security mechanism, i.e. we prevent all unauthenticated access to Lambdas (in case there are any exploits that could be executed through OPTIONS in Lambda code/dependencies). |
Seeing the same as @Jun711 - Is the issue not that this should be also added to https://github.com/awslabs/aws-serverless-express/blob/master/examples/basic-starter/simple-proxy-api.yaml#L87 |
Solution from this link: CodeGenieApp/serverless-express#58
@Jun711 revisiting this I realized your PR only modified the |
@brettstack ok, will do. Has the folder structure been changed? |
Yes it's now in examples/basic-starter |
Thanks @Jun711. This has been merged into develop branch and we'll merge into master soon. Closing. |
@brettstack would you explain this" remove the OPTIONS method and redeploy your API and let Express deal with CORS." |
By adding the contentHandling I am getting the |
If an API uses contentHandling: CONVERT_TO_BINARY anywhere, the generated mock integrations for CORS would fail with a 500 error. This turned out to be due to a missing CONVERT_TO_BINARY attribute. Ref: CodeGenieApp/serverless-express#58 (comment)
If an API uses contentHandling: CONVERT_TO_BINARY anywhere, the generated mock integrations for CORS would fail with a 500 error. This turned out to be due to a missing CONVERT_TO_BINARY attribute. Ref: CodeGenieApp/serverless-express#58 (comment)
Had anyone same issue? When I try via postman make a request method OPTIONS the response is
{"message": "Internal server error"}
if I try in API Gateway Console, lambda Console, npm run local and npm run invoke-lambda the response is ok. Any idea what is the problem?The text was updated successfully, but these errors were encountered: