Create a static site in AWS with a custom domain, SSL certificate, and proper redirects using CloudFormation.
Read an extensive post about this repo
Please update the package.json
per your needs.
The create-stack
command is as below:
aws cloudformation create-stack \
--stack-name STACK_NAME \
--template-body file://template.yml \
--profile AWS_PROFILE \
--region us-east-1 \
--parameters ParameterKey=DomainName,ParameterValue=DOMAIN_NAME ParameterKey=HostedZoneId,ParameterValue=HOSTED_ZONE_ID
Where
STACK_NAME
- is your stack nameAWS_PROFILE
- is your credentials profile in theDOMAIN_NAME
- is your domain name (the naked domain, e.g. example.com)HOSTED_ZONE_ID
- is your Route53 zone for the domain, should look like Z07414553OA4KK51T5EZA
The deploy
command will deploy your static site to the S3 bucket and invalidate the CloudFront cache. You may update as per your needs, by default the copy command excludes all paths in the current folder, in order to prevent deploying sensitive info.
aws s3 cp ./ s3://S3_BUCKET_NAME \
--acl public-read \
--profile AWS_PROFILE \
--recursive \
--exclude "*" \
--include index.html \
--include 404.html \
&& aws cloudfront create-invalidation \
--profile monithor \
--distribution-id DISTRIBUTION_ID \
--paths "/*"
Where:
S3_BUCKET_NAME
- is your S3 bucket nameAWS_PROFILE
- is your credentials profileDISTRIBUTION_ID
- is your CloudFront distribution ID