-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add comment about CORS in todos-lambda #130
Conversation
@@ -44,11 +44,16 @@ struct AppLambda: APIGatewayLambdaFunction { | |||
router.get("/") { _, _ in | |||
return "Hello" | |||
} | |||
|
|||
// When enabling Lambda function URLs, CORS can be configured at the AWS level, and there's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should make it clear this is APIGateway (maybe add a link), otherwise this is cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adam-fowler so I also thought this is APIGateway when I first saw it, but it turns out it's not exactly API Gateway (at least not publicly):
https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html
https://www.serverlessguru.com/blog/aws-lambda-function-urls-vs-amazon-api-gateway
I could link to this section in the first link, what do you think?
https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html#urls-cors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use APIGateway to access Lambda’s not function URLs. So I would have thought it would be related to this https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html. Did you check the APIGateway CORS setup after deployment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest what is the input to the lambda if you use a function URLs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check the APIGateway CORS setup after deployment?
I checked API Gateway, and there's no entry there for this function - it's all handled by Lambda:
Here's where it's defined:
Out of interest what is the input to the lambda if you use a function URLs?
If I understand the question correctly, the input is still a APIGatewayV2Request
.
While testing something with a lambda, I noticed I had twice the
Access-Control-Allow-Origin
header, and it led to CORS errors when calling my lambda function from the browser.Upon investigation, I found that it was due to CORS being set both at the code level, and at the Lambda function URL configuration level. When it's configured in the Lambda URL, there's no need to setup
CORSMiddleware
.This PR adds a comment about it in the todos-lambda sample project.