To create a new URL redirect, login to AWS and access the S3 console:
- Create a new bucket.
- Use the domain name for the Bucket name (example: domain.com).
- Deselect the Block all public access checkbox.
- Select Create bucket.
- Open your newly created bucket, and select Permissions. Select Edit on the Bucket policy and paste the following. Be sure to update the domain.com to your bucket name. Save your changes.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::domain.com/*"
}
]
}
-
On the bucket select Properties and scroll down to the section Static website hosting and click Edit.
- Enable Static website hosting
- Select Redirect requests for an object.
- In the Host name field, enter the redirected destination.
- Under Protocol, select https.
- Save changes.
-
Access the CloudFront console and select Create distribution.
- Origin domain will be the S3 bucket static hosting URL, do not use the autocompleted suggestions as these wont work. (example: domain.com.s3-website.us-east-2.amazonaws.com)
- Viewer protocol policy select Redirect HTTP to HTTPS.
- Alternate domain name (CNAME) select Add item. Add both domain.com and www.domain.com to the list.
- Custom SSL certificate, select Request certificate.
- Request a public certificate and click Next.
Use domain.com as the Fully qualified domain name. - Add another name to this certificate and use www.domain.com
- Select DNS validation and Request.
- Select the request, and click Create records in Route 53, then Create records.
- Request a public certificate and click Next.
Under Custom SSL certificate in CloudFront, select the newly created SSL certificate. Then Create distribution.
-
Access the Route53 console, and select Hosted zones. Then select the zone for domain.com.
-
Select Create record
- Select Alias. Then Choose endpoint and select Alias to CloudFront distribution.
- Select your domain.com under Choose distribution.
- Create a second A record for www using the same settings listed above.