Deploy a SPA with AWS Codebuild using aws-cdk
This is an aws-cdk project where you can deploy any SPA (React, Angular, Vue, etc.) via Codebuild on S3 and served via Cloudfront.
Link to the tutorial that I’ve written: https://dev.to/ryands17/deploying-a-spa-using-aws-cdk-typescript-4ibf
Note: This configuration is for GitHub only. For Bitbucket, you can edit the source accordingly.
Prerequisites
default
). The credentials generated should have access to creation of all resources mentioned else it won’t work.Steps
.example.env
file to .env
and replace all the values with predefined values for your stack.Note: All the variables are mandatory! Without that, the stack wouldn’t work.
Run yarn
(recommended) or npm install
Run yarn deploy --profile profileName
or npm run deploy -- --profile profileName
to deploy the stack to your specified region. You can skip providing the profile name if it is default
.
You can start the build from the console in Codebuild
and view your website on the Cloudfront provided URL!
The cdk.json
file tells the CDK Toolkit how to execute your app.
yarn build
compile typescript to jsyarn deploy
deploy this stack to your AWS account/region specified in the .env
yarn watch
watch for changes and compileyarn test
perform the jest unit testscdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template