Clean URLs For Amazon S3 Bucket Contents Using Route 53 Alias - amazon-web-services

I am currently building a static website for a small startup and decided to us S3 to host it, and have the Domain registered through Route 53.
I have already setup the Bucket as mysite.net within S3, populated by index (I have it is as main.html) and error document. The main.html is within a folder called main so I setup a Website Redirect Location Metadata rule that pointed to the full S3 URL where it is located (https://s3.us-east-2.amazonaws.com/mysite.net/main/main.html).
All of the content has been Made Public, I have my Bucket Policy set up as:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mysite.net/*"
}
]
}
And all should be ready to go. In Route 53 I have the Domain successfully registered for the last few days, with the hosted zone for mysite.net already created, and I have set up an "A Record" IPV4 Alias pointing to the bucket address within S3.
When I got to type in mysite.net in the address bar I get sent to my error.html document, which is better than a 403 - but when I click the Home tab within that document it leads me to my S3 bucket as https://s3.us-east-2.amazonaws.com/mysite.net/main/main.html
My question is two fold:
1) What did I do wrong for mysite.net to continually redirect to error.html
2) How can I ensure I will have Clean URLs throughout - it will look unprofessional if I can go to mysite.net pull up the main page, then click the Contact tab and get send to https://s3.us-east-2.amazonaws.com/mysite.net/contact/contact.html
I have read Site domain redirecting to the url of amazon web services bucket as well as URL Forwarded instead of Masked with AWS S3 Static Site via Route 53 to no avail, and have combed over the S3/Route 53 Docs for static hosting and still am having issues.

Related

Correct way to host SPA using S3, Cloudfront and Route53

I built a react app and am trying out different hosting services. Using an s3 bucket to store files then using cloud front distribution seems solid so I'm trying it out.
I built my React app and added this script to package.json
aws s3 sync build/ s3://<bucket-name>
Then I created a distribution network using the bucket name endpoint that was listed under s3 properties and that status now says deployed.
Now I have a domain name that I purchased on Godaddy. I changed the nameserver's to the 4 provided by AWS Route53 in the Hosted Zone. This also created 2 record sets. I then added a 3rd record set, ALIAS and the target is the cloudfront.net url.
Now I'm seeing two different results.
On safari browser, Safari throws a 403 Error.
On chrome I get a message saying "Your connection is not private" even though I can view the valid cloudfront certificates in the url bar.
I have bucket policy on my s3 that looks like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::<bucket-name>/*"
]
}
]
}
Was there something I missed?

How do I point a domain hosted at Name.com to an AWS S3 Static Website?

I'm trying to allow AWS Route 53 to manage a domain I bought on Name.com so I can apply the domain to an AWS bucket that is hosting a static website.
I've attempted to follow the outlined instructions from this post which I'm guessing is out of date (Domain name setup with AWS S3 bucket with static hosting)
Create the hosted zone with your domain name, domain.com
Create an A record for your domain. On the right side you'll see a radio button "Alias" choose yes, then click into the target box and wait for your bucket to appear under S3 Website endpoints. (More on this below).
Select your bucket and click create.
Head over to your registrar, NameCheap and configure the nameservers to use the AWS nameservers in the NS record from your AWS hosted zone.
Your bucket name must match the domain name.
In the properties tab, you need to enable the static website hosting option and provide your index page.
In the permissions tab, click on bucket policy, then click the policy generator link at the bottom.
In the policy generator, select S3 as the type of policy
Set the principal to *
Set the action to Get Object
set the ARN to the ARN for your bucket /*. For example arn:aws:s3:::domain.com/*
Click Add statement, then generate policy and paste that into the bucket policy and save.
But I'm having an issue with last point 7. Applying the generated policy to the bucket policy, it is throwing the following error:
Action does not apply to any resource(s) in statement
We would suggest try below policy for your bucket which is provided by AWS
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::example-bucket/*"
]
}
]
}
Replace example-bucket with your bucket name
Navigate through below link How Do I Configure an S3 Bucket for Static Website Hosting?

AWS Bucket Policy Invalid Resource

I'm having some trouble with AWS Bucket policies, I followed the instruction and it doesn't let me set the policy, so I can't get my domain to work with the buckets.
Here is a picture. The tutorial told me to replace example.com with my bucket name.
I've been trying to set up my buckets with my domain for over a month now and I just can't seem to get it going. I already purchased my domain, and it's the exact domain name I want, so I don't want to be forced to go to Bluehost with a new domain.
It is quite simple:
Your bucket is called www.justdiditonline.com
Your bucket policy is attempting to create a rule for a bucket named justdiditonline.com
The bucket names do not match
Solution: Use a policy with the correct bucket name:
{
"Id": "Policy1",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::www.justdiditonline.com/*",
"Principal": "*"
}
]
}
I notice you have another bucket called justdiditonline.com. Your existing policy would work on that bucket.
The Setting Up a Static Website Using a Custom Domain instructions detail what to do, and they work fine with an external DNS service using a CNAME to point to the static website URL. The main steps are:
Create a bucket with the domain name www.justdiditonline.com
Add a bucket policy to make content public, or make sure the individual objects you want to serve are publicly readable
Activate Static Website Hosting on the bucket, which will return a URL like: www.justdiditonline.com.s3.amazonaws.com
Create a DNS entry for www.justdiditonline.com with a CNAME pointing to the Static Website Hosting URL

Static Site Deployment in AWS S3 with CloudFront

I am trying to set up a static website that has been configured to use index.html default documents. I have the following bucket policy set up in S3:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "Allow Public Access to All Objects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.risendeadmc.com/*",
"Condition": {}
}
]
}
The 2nd step is I created a CloundFront distribution to distribute this S3 content.
Issue 1: Sub folders are still accessible by CDN domain name but index.html no longer load as default for document and hitting folder causing a content download.
I then set up a A record Alias to the CDN distribution in Route53 and now nothing resolves with a 403 Forbidden error no matter what I use.
Any configuration advise to resolve would be greatly appreciated.
What I am looking for is the ability to use my domain set up in Route53 to point to the CloudFront Distribution to provide access (with index.html default) content access.
I would like to keep root and sub folder default access points to non file suffixed endpoint reference:
http://mydomain.com/root
or
http://mydomain.com/root/sub/subroot
rather than address index.html
You will want to make sure that you are setting your default root object in Amazon S3 and that your origin is the S3 Website endpoint.
Example origin: www.example.com.s3-website-us-east-1.amazonaws.com
http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html

how appoint a subdomain for a s3 bucket?

Good morning,
I am using amazon s3 bucket as the image server.
And I want to use a subdomain of my site, how to address this bucket.
eg: a picture is now in: https://s3-sa-east-1.amazonaws.com/nomeBucket/pasta/imag.png, and I access it through this same link.
Would that it were so: imagens.mydomain.com.br / folder / imag.png
Is there any way I can do this? appoint a subdomain address to a bucket?
I've tried the amazon route 53, as CNAME. I tried this: https://s3-sa-east-1.amazonaws.com/nomeBucket/
I took the test yesterday, but apparently it did not work.
Someone already did something similar, and / or know how to help me?
Note: I'm using nginx. also need to configure it for subdomain?
Thank you
You need to rename your bucket to match the custom domain name (e.g. imagens.mydomain.com.br) and set up that domain as a CNAME to
<bucket-name>.s3.amazonaws.com.
(in your case imagens.mydomain.com.br.s3.amazonaws.com.
The full instructions are available here:
http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
Update 2019 : AWS SUBDOMAIN hosting in S3
As of today following steps worked to have a successfully working subdomain for AWS S3 hosted static website:
Create a bucket with subdomain name. In this example www.subtest.mysite.com
Note: Make sure on 'Permission' tab of bucket:
1.Block public access (bucket settings)
2.Access Control List &
3.Bucket policy
are appropriately set to make sure bucket is public. ( Assuming you already did this for your root domain bucket, those settings can be mirrored on this subdomain bucket)
Upload the index.html file in the bucket
Create a CNAME record with your domain provider
I'm going to build on the other answers here for completeness.
I have moved my bucket to a subdomain so that the contents can be cached by Cloudflare.
Old S3 Bucket Name: autoauctions
New S3 Bucket Name: img.autoauctions.io
CNAME record: img.autoauctions.io.s3.amazonaws.com
Now you'll need to copy all of your objects since you cannot rename a bucket. Here's how to do that with AWS CLI:
pip install awscli
aws configure
Go to https://console.aws.amazon.com/iam/home and create a user or go to an existing user
Go to the user's Security credentials tab
Click Create access key. Copy the secret.
Here's a list of AWS regions.
Now you'll copy your old bucket contents to your new bucket.
aws s3 sync s3://autoauctions s3://img.autoauctions.io
I found this to be too slow for the 1TB of images I needed to copy, so I increased the number of concurrent connections and re-ran from an EC2 instance.
aws configure set default.s3.max_concurrent_requests 400
Sync it up!
Want to make folders within your bucket public? Create a bucket policy like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::img.autoauctions.io/copart/*"
},
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::img.autoauctions.io/iaai/*"
}
]
}
And now the image loads from img.autoauctions.io via Cloudflare's cache.
Hope this helps some people!