简体   繁体   中英

Pointing multiple Route53 subdomains to a single S3 bucket

I have a Route53 subdomain (test.site.co.uk) and I want to be able to point it at a main S3 bucket (testing.uat.co.uk). I will also have more subdomains soon needing to do the same thing.

I cannot set the Alias Target to the S3 bucket because it is a different name which it needs to be. I am changing the content displayed on the bucket's site to respond to the targetted URL. For this reason, I need to keep the URL because I have also tried to redirect a bucket of the same name to the domain of the main bucket but that changes the URL.

Is there any way around this where I can keep the targeted domain?

The ideal approach to do is using Amazon CloudFront with Lambda@Edge. In CloudFront, you can set multiple Alternate Domain Names (CNAMEs) and with Lambda@Edge you can process the request to display different content:

 import json

 def lambda_handler(event, context):
     request = event['Records'][0]['cf']['request']
     headers = request['headers']

     if request['domainName'] == 'example1.com':
         # Do this 1
     elif request['domainName'] == 'example2.com':
         # Do this 2
     else:
         # Do this else

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM