Clear the cloudfront cache every time you make changes to your s3 bucket.
aws cloudfront create-invalidation --distribution-id #{distribution_id} --paths "/* https://stackoverflow.com/questions/65286352/invalidate-cloudfront-cache-with-aws-cdk-pipelines
Here are the steps to host your site with an ssl certificate over https and through a cloudfront CDN.
- Turn off "Block all public access"
- If you would like to use s3 for static website hosting and purchasing your own domain, include the top-level domain name in the name. Example: my-site.com.
- Click create. Under the properties tab, scroll to tthe bottom and enable static website hosting. Enter the entry point for the app. Ex. index.html
- In the permissions tab, give access for your resource to the following actions.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::#{s3bucketname}"
},
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:DeleteObject",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload"
],
"Resource": "arn:aws:s3:::#{s3bucketname}*"
}
]
}
- Request an ssl cert for your domain name. You can include www.my-site.com and my-site.com
- Cache your static site over a cloudfront distribution.
- Select your ssl cert.
- Enter your default root object (index.html);
- Add any custom CNAMEs
- Purchase a domain name and add a hosted zone for it. Ex. my-site.com
- If you have an IPV6 address. Create 2 records in your hosted zone. An A record for IPv4 and an AAAA record for IPv6.