CloudFormation template that defines a CodePipeline and associated CodeBuild projects to fascilitate deployment of a ReactJS frontend web application from a shared-services account to development and production accounts. The ReactJS application is deployed to serverless infrastructure backed by CloudFront distribution and S3 Bucket (CloudFront configured to use S3 Origin).
The pipeline was built and tested with the cf-react-cors-spa project and can be adapted to work with other ReactJS projects that follow a similar project structure and package manager.
- Developer commit code to the 'monitored branch' (default: main) of the CodeRepository.
- CodePipeline executes in response to the newly committed code.
- Pipeline retrieves source from CodeCommit Repository.
- CodeBuild installs required dependencies using the yarn package manager and creates ReactJS production build artifacts.
- CodeBuild assumes the cross account role in the Development account.
- CodePipeline creates/updates the CloudFormation stack that defines the AWS resources used to run the ReactJS application.
- CloudFormation creates/updates the S3 bucket.
- CloudFormation creates/updates the CloudFront Distribution.
- CodePipeline syncs ReactJS production build artifacts to the S3 bucket in the Development account.
- CodePipeline invalidates the cache of the CloudFront distribution (forcing it to serve the latest content from the S3 bucket).
- Mandatory approval step for deployment to production environment.
- -> 18. Repeats steps 5 - 10 for the production environment.
cross-account-deployment-role.yml
: CloudFormation template for deploying cross-account roles. This template is intended to be deployed to the development and production accounts.
pipeline-reactjs.yml
: CloudFormation template that creates a CodePipeline and associated ClouBuild resources for building and deploying the ReactJS Application. This template is intended to be deployed to the shared services account.
repository.yml
: Helper template used to create a CodeCommit repository to store the ReactJS application for use with the pipeline-reactjs.yml
template. This template is intended to be deployed to the shared services account.
- Deploy the
cross-account-deployment-role.yml
template into your development and production accounts to create the cross-account roles that will be assumed by the pipeline.
ExternalAccountId: <YOUR SHARED SERVICES ACCOUNT ID>
- Deploy the
repository.yml
template into your Shared Services account to create a new repository.
RepositoryName: my-repository
-
Populate the repository's
main
branch with contents of the cf-react-cors-spa project. -
Deploy the
pipeline-reactjs.yml
template into your shared services account
CodeCommitRepositoryName: my-repository
BuildBranch: main
DevDeploymentCrossAccountRoleArn: arn:aws:iam::<YOUR DEV ACCOUNT ID>:role/crossaccount-deployment-role
ProdDeploymentCrossAccountRoleArn: arn:aws:iam::<YOUR PROD ACCOUNT ID>:role/crossaccount-deployment-role
DestinationStackName: react-cors-spa
CloudFormationFile: react-cors-spa-stack.yaml
DeploymentRegion: us-east-1