3 Answers
- Newest
- Most votes
- Most comments
0
If you use origin access control for authorization of the access to the origin bucket, you may solve the issue by changing the authorization method to origin access identity. Of course, you should modify bucket policy for all other buckets that you use in your Lambda@Edge.
answered a year ago
0
Region in response is wrong. I updated lambda code and works for me.
Try this:
us_bucket = "cdn-origin-bucket-us-east-1-XXXX.s3.us-east-1.amazonaws.com"
eu_bucket = "cdn-origin-bucket-eu-west-1-XXXX.s3.eu-west-1.amazonaws.com"
# ap_bucket = "mybucket-ap.amazonaws.com"
default_bucket = "cdn-origin-bucket-us-east-1-XXXX.s3.us-east-1.amazonaws.com"
# Regions Mapping
regions_mapping = {
# NA
"us-east-1": us_bucket,
"us-east-2": us_bucket,
"us-west-1": us_bucket,
"us-west-2": us_bucket,
"ca-central-1": us_bucket,
# EU
"eu-central-1": eu_bucket,
"eu-central-1": eu_bucket,
"eu-west-1": eu_bucket,
"eu-west-2": eu_bucket,
"eu-west-3": eu_bucket,
"eu-north-1": eu_bucket,
}
def lambda_handler(event, context):
request = event['Records'][0]['cf']['request']
# Identify edge region
lambda_region = context.invoked_function_arn.split(':')[3]
# Get S3 bucket based on regions mapping
domain_name = regions_mapping.get(lambda_region, default_bucket)
bucket_region = domain_name.split('.')[2]
# Update origin request object
request['origin']['s3']['domainName'] = domain_name
request['origin']['s3']['region'] = bucket_region
request['headers']['host'] = [{'key': 'host', 'value': domain_name}]
return request
answered a year ago
-1
Try using this code to get the region more effectively:
import os
def lambda_handler(event, context):
runtime_region = os.environ['AWS_REGION']
answered a year ago
Relevant content
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
I'm afraid this doesn't adress the issue, but thanks for the input