-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Cloud front: running lambda@edge sends bucket to wrong s3 region #31618
Comments
@anthonyLock Good afternoon. Thanks for reporting the issue. Looks like you are using the custom handler for your Lambda function. Please confirm the following:
Thanks, |
The error message is shown when I do a request to the cloud front URL after everything is deployed. It is in the response. I am using the typescript The lambda is not making any SDK request but is checking a cookie that is a JWT from cognito, using I am getting cloudwatch logs saying the execution time with it running successfully. After some further digging I tried the following in my typescript code changing returning the event to using the callback. This worked
In all the exmples on this page https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html they use the callback function given. However according to https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html#typescript-handler-callback it says Knowing this I may have created a issue in the wrong place. Please let me know if it is more appropriate to recreate it elsewhere, |
@anthonyLock Good morning. I'm assuming you took the Lambda handler code from https://aws.amazon.com/blogs/networking-and-content-delivery/using-amazon-cloudfront-and-amazon-s3-to-build-multi-region-active-active-geo-proximity-applications/ where it is setting S3 bucket region as below: # Update origin request object
request['origin']['s3']['domainName'] = domain_name
request['origin']['s3']['region'] = lambda_region
request['headers']['host'] = [{'key': 'host', 'value': domain_name}] This appears to be setting bucket region to lambda region. And as you mentioned, Lambda and S3 bucket are in different regions. So it gives the mentioned error since S3 bucket is being accessed from a different region (Lambda region). I'm unsure if using callback as opposed to Thanks, |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the bug
I have a bucket in eu-west-2 and have recently created a cloudfront distribution and lambda@edge to serve the content. The lambda is a viewer request. The lambda@edge and cloudfront are in us-east-1.
For an authentication step I have added in a lambda following the following blog post https://aws.amazon.com/blogs/networking-and-content-delivery/authorizationedge-using-cookies-protect-your-amazon-cloudfront-content-from-being-downloaded-by-unauthenticated-users/
The Bucket is defined in a different CDK stack.
I have got everything working great without the lambda and cloudfront delivers the content as expected. However as soon as I add in the lambda I am getting the following message
I have followed the advice in this issue #9556 and still having the same problem.
My lambda code is
My CDK looks like
I also have all the permissions and bucket policies but have not added to above as the cloudfront is working without the EdgeLambdas so I am pretty sure it is not due to that.
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
Expect to serve the content both with and without the lambda running
Current Behavior
Reproduction Steps
I have also tried changing Origin to a group
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.160.0 (build 7a8ae02)
Framework Version
No response
Node.js Version
v18.18.2
OS
ubunbu on wsl
Language
Go
Language Version
1.23
Other information
No response
The text was updated successfully, but these errors were encountered: