Static website hosting infrastructure on AWS by CDK. Deploys react source code to S3, serves website with low latency content delivery network with an origin access identity and Lambda@Edge. Secured by HTTPS (SSL/TLS) with certificate manager(ACM), and attaches it to the CloudFront distribution. Also secures cloudFront distribution with web application firewall (WAF) from common web-based attacks. This solution also includes two pipelines, one for cdk code infrastructue, and one for react codebase.
aws secretsmanager create-secret --name demoapp/gitSourcetoken --secret-string <GITHUB_TOKEN>
Or
aws secretsmanager update-secret --secret-id demoapp/gitSourcetoken --secret-string <GITHUB_TOKEN>
export AWS_ACCESS_KEY_ID=<XXXX>
export AWS_SECRET_ACCESS_KEY=<XXXX>
export AWS_DEFAULT_REGION=<XXXX>
"settings": {
"locations": ["US"],
"region": "<Region for distribution>",
"domainName": "<Url link route53>",
"hostedZoneId": "<Host zone id form route53>"
},
// React app source code
"project_source": {
"branch": "main",
"owner": "<OWNER>",
"repo": "<REPO>",
"secretToken": "<setup in next step>",
},
// Cdk infrastructure code
"cdk_source": {
"branch": "main",
"owner": "<OWNER>",
"repo": "<REPO>",
"secretToken": "<setup in next step>",
}
- Install
npm install
- deploy
cdk deploy
On Initial Deployment: Cdk pipeline will fail to prevent repeate deployment
alias cdk="npx aws-cdk"
aws cloudfront get-distribution-config --id ${id} | jq '. | .DistributionConfig' > /tmp/disable-distribution-${id}
Or
aws cloudfront delete-distribution --id ${id} --if-match \
$(aws cloudfront get-distribution-config --id ${id} | jq .ETag -r)