Skip to content

Instantly share code, notes, and snippets.

@johnlauck
Last active June 27, 2016 19:53
Show Gist options
  • Save johnlauck/121ca65bbcf87a31df24ebaea327f645 to your computer and use it in GitHub Desktop.
Save johnlauck/121ca65bbcf87a31df24ebaea327f645 to your computer and use it in GitHub Desktop.
How to simply redirect an S3 bucket to any URL

Given a vanity/campaign URL, this is the simplest way to provide a server side redirect with 0 infrastucture overhead:

  1. Create a bucket
  2. Open GET access to the bucket as shown below in bucket-policy-example.json (more info available in AWS S3 Static Hosting docs)
  3. Enable website hosting on the bucket
  4. Under Edit Redirection Rules, add XML similar to routing-rules.xml below. Read more about Routing Rules for additional options.
  5. Assign an A record in Route 53 by aliasing the bucket.
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadForGetBucketObjects",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::example-bucket/*"
]
}
]
}
<RoutingRules>
<RoutingRule>
<Redirect>
<Protocol>https</Protocol>
<HostName>example.com</HostName>
<ReplaceKeyWith>/your/epic/path</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment