I'm trying to add HTTPS to my static website hosted in an S3 bucket with a domain bought from Google's Domains. I know that in order to set up CloudFront Distribution, I need to send the SSL Cert from AWS Certificate Manager to Google.
This is what I did:
From AWS Certificate Manager:
*.myweb.com
and myweb.com
, following this answer here.Name
, Type
and Value
for my CNAME.I've looked at guide here, here, here and here without any luck.
Update 10 May:
Many thanks to @hephalump for his help. In addition to his answer, he sent to me this super helpful link from AWS.
In my case, it was slightly different from the video by Geoff:
Name: mywebsite.com - Type: A - Value (ALIAS target): CloudFront Distribution (from the list).
Name: www.mywebsite.com - Type: A - Value (ALIAS target): mywebsite.com (on the bottom of the list).
and now it works.
You can use Amazon S3 to host a static website. On a static website, individual webpages include static content. They might also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts, such as PHP, JSP, or ASP.NET.
The following Google services automatically issue, install, and renew SSL/TLS certificates at no additional cost: Google Sites. Google Business Profile.
Since you're using AWS services, you may wish to seriously consider using Route53 for your DNS; it will make your life a lot easier.
Even if you're not using Route53 can still use the DNS validation method to validate your certificate. Alternatively, if that's not working, you can use the Email verification method which is also very reliable.
To use the DNS validation method with Google domains you would do the following:
On the AWS Certificate Manager certificate confirmation screen get something like:
NAME:
_3341936be9c722351e9e3345d5118ee28.yourdomain.com.
TYPE:
CNAME
VALUE:
_3341936be9c722351e9e3345d5118ee28.ltfvzjuylp.acm-validations.aws.
Head over to Google domain manager and go to the Custom Resource Records section. In the first field enter _3341936be9c722351e9e3345d5118ee28
. In the dropdown menu select CNAME. In the TTL enter 1H
. In the data field enter _3341936be9c722351e9e3345d5118ee28.ltfvzjuylp.acm-validations.aws
. Finally, click Add.
Then wait. You have to wait for the DNS record to propagate, and you have to wait for ACM to check it. It could take up to 1 hour.
EDIT: Since it seems you're using Route53 to handle your DNS this is really easy. Regardless of where your bucket is, make sure you request your certificate in the US-EAST-1 (N. Virginia) region. Follow all the request steps and on "Step 4: Validation", when the certificate is generated click on "Create record in Route 53". Wait 5 minutes and if Route53 is indeed handling your DNS then your cert will be ready to use.
You will eventually only allow permission for an OAI, as mentioned earlier with blocking that you do not want people to be able to reach your S3 bucket directly, and only reach your website through your domain name that will have https when S3 buckets are http, but for testing purposes if you want to, go ahead and do the following. In Permissions, in Bucket policy, select edit and put this, again we will change this once we have an OAI:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.<your website name>.com/*"
}
]
}
If you forget to enable static website hosting before connecting to your CloudFront distribution, it will result in this error when trying to view your website: If this happens, you can try reconnecting your CloudFront distribution to your S3 bucket to re-register things so to speak. Don't know why this is.
Head over to certificate manager
VERY IMPORTANT: Change from your current location to US East (N. Virginia) us-east-1. The certificate must be requested from this region, no matter what. If you don’t, and instead have Northern California for example, when you move onto the next step which is Cloudfront, your ssl certificate will not show up and you will not be able to complete your HTTPS setup. Not entirely sure why this is, but to use CloudFront, the region for your certificate must be US East (N. Virginia) us-east-1.
_123a456789012b3456c7d8ef901a234b.www
, Type: CNAME
, DATA something like: _fe098765432dc10b987a65f43e21098d.abcdefghij.acm-validations.aws.
For me it took 4 minutes after routing things up in Google Domains to get my certificate issued. So sip that coffee and take a breather while you wait! It shouldn't be long.
The certificate status will change to "Issued".
Head over to CloudFront in AWS.
Now go to the hosted zone details if you have not already been taken there. You will now create a record to connect to our CloudFront distribution to add to the list of two records that you should already have there in your hosted zone.
You are now done with the AWS side.
You need to create a CNAME record for www.<your website name>.com for connecting to your Cloudfront distribution, and a redirect from <your website name>.com to www.<your website name>.com so that your users can put in your naked domain name and still get to your site. If google domains supported ANAME/ALIAS records, you could do things differently, where you could also create a Cloudfront distribution for your naked domain of <your website name>.com and route <your website name>.com to it's own CloudFront distribution within Google Domains. But since Google doesn’t support ANAME/ALIAS records, you have to redirect your naked domain to your domain, and then your domain to your CloudFront. Also you would have to create an s3 bucket for your naked domain, in which you could point it to the other s3 bucket. But you don’t have to worry about that, since Google Domains doesn’t support ANAME/ALIAS records in the first place. And if it makes you feel any better, amazon.com redirects to www.amazon.com, so having a naked domain redirect to a www url is not only common but used by the big guys.
Now this is fun, the AWS docs at the time of writing this say create a Synthetic Record within Google Domains, but Google Domains recently changed their interface. It no longer calls them "Synthetic records" which was within their "DNS" page, instead you you have to:
I blocked out my info, and also put in fake sample data for you to get an idea of what your AWS records are supposed to look like in Google Domains.
So when someone goes to <your website name>.com, Google Domains redirects it to www.<your website name>.com which then does a CNAME lookup and finds your CloudFront distribution url. From CloudFront which has your SSL certificate, Route 53 sees that the CloudFront distribution was reached and serves your S3 bucket static site.
Now that you have it so that your users can access the S3 bucket through your domain name using https, you want to turn off the bucket from being accessed directly (which is http and not https among other reasons). So, first go to CloudFront.
JSON for OAI, which should have been set if you selected "Yes, update the bucket policy" in the previous step. I added "s3:PutObject" in list of actions as shown below
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "2",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity <your OAI ID>"
},
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "[resource_name]"
}
]
}
And now users should only be able to enter your static website via CloudFront and not directly through your S3 bucket.
I was trying the same, by adding CNAMEs using Google domain DNS manager. For me the issue was, instead of adding just the alphanumerical part, I was adding the entire string including the domain. Once I removed that, I believe, it might have taken less than an hour. Go through the below link and pay special attention to the one under 'important' section. https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-validate-dns.html
From the above link.
The CNAME information that you need does not include the name of your domain. If you include your domain name in the DNS database CNAME record, validation fails. For example, the displayed Name may resemble the following:
_a79865eb4cd1a6ab990a45779b4e0b96.yourdomain.com However, the required CNAME information only includes the following:
_a79865eb4cd1a6ab990a45779b4e0b96
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With