DNS redirection to URL through Route 53 and S3

I recently needed to redirect a DNS (like links.sportscafe.in) to a path (like http://trello.com/abc). Here is what finally helped me: http://stackoverflow.com/a/14289082/1233476

The TTCBER (Thing That Cannot Be Easily Replicated) was the following redirection rule in S3:

1
2
3
4
5
6
7
8
9
10
<RoutingRules>
<RoutingRule>
<Redirect>
<Protocol>https</Protocol>
<HostName>myaccount.signin.aws.amazon.com</HostName>
<ReplaceKeyPrefixWith>console/</ReplaceKeyPrefixWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>

Other TTCBERs:

To allow public access to S3 resources from any webpage (which you may would want in case hosting public assets for a website), we need to add the following bucket policy to the bucket:

1
2
3
4
5
6
7
8
9
10
11
12
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::cdn-static.mybucket.name/*"
}
]
}

To allow these resources to be embedded in all websites, add CORS configuration to the S3 bucket:

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

Author

Sahil Ahuja

Posted on

2016-12-17

Updated on

2020-12-21

Licensed under

Comments