3 Respostas
- Mais recentes
- Mais votos
- Mais comentários
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.
respondido há 9 meses
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
respondido há 8 meses
-1
Try using this code to get the region more effectively:
import os
def lambda_handler(event, context):
runtime_region = os.environ['AWS_REGION']
respondido há um ano
Conteúdo relevante
- AWS OFICIALAtualizada há 2 anos
I'm afraid this doesn't adress the issue, but thanks for the input