Previously, this blueprint used Route53 records associated with a static web hosting-enabled S3 bucket. The trade-off of this pattern was it only supports HTTP
protocol. Red flag 🚩
Nowadays, there are much better options using Amazon CloudFront and CloudFront function. It's still serverless and supports HTTPS
natively. It also enables new capabilities thanks to the newly released KeyValue Store feature in CloudFront.
This revised version will let you redirect subdomains to any other top-level domain, subdomains or URL.
- URL Redirect: Redirect multiple source subdomains to target URLs
- Easy URLs Management: Manage target URLs directly using the CloudFront AWS Console
Examples:
blog.zoph.io
->https://zoph.me
asd.zoph.io
->https://awssecuritydigest.com
book.zoph.io
->https://calendly.com/zophio/30min-meeting/
ℹ️ The following assets will be deployed to your AWS account.
- CloudFront Distribution
- CloudFront Function
- CloudFront KeyValueStore
- S3 Buckets
- S3 Bucket Policy
- Route53 Records
ℹ️ Fill the following parameters in the
Makefile
with your own values.
###################### Parameters ######################
ProjectName := "my-project-name" # Give a name for your project
AWSRegion := eu-west-1 # AWS Region used for deployment
SourceNakedDomain := domain.tld # Source domain
SourceSubDomainList := "sub1,sub2" # Source subdomains
R53HostedZoneId := Z1BPJ52MEEXXXX # Source domain R53 hosted zone id
# Use Wildcard Certificate if multiple subdomains
CertificateArn := "arn:aws:acm:us-east-1:...." # us-east-1 Arn of ACM Public Certificate associated
#######################################################
ℹ️ Update the
config.json
file according to your needs
{
"data": [
{
"key": "sub1.domain.tld",
"value": "google.com"
},
{
"key": "sub2.domain.tld",
"value": "aws.amazon.com/cloudfront/"
}
]
}
ℹ️ Run the following command (where your AWS CLI is authenticated)
$ make requirements
$ make deploy
Give a try with this command:
$ make test
ℹ️ You will be able to change target url using the CloudFront Console, in the KeyValueStores section
$ make tear-down
- 🏴☠️ AWS Security Boutique: zoph.io
- 💌 AWS Security Digest Newsletter
- 🐦 𝕏/Twitter: zoph