Skip to content
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

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

natanrolnik
Copy link
Contributor

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.

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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:

Safari-2024-10-27-14 35 16@2x

Here's where it's defined:

Safari-2024-10-27-14 36 46@2x

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.

@adam-fowler adam-fowler merged commit 158aee7 into hummingbird-project:main Oct 29, 2024
1 check passed
@natanrolnik natanrolnik deleted the patch-1 branch October 30, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants