This project contains both backend and frontend infrastructure defined using AWS CDK. It automates the deployment of your backend resources and frontend code using AWS CodePipeline, AWS CodeCommit, and AWS CodeBuild.
The project consists of two main CDK stacks:
- AppCdkStack: This stack defines the backend infrastructure, including your Lambda functions, DynamoDB tables, API Gateway, etc.
- AppPipelineStack: This stack sets up the CI/CD pipeline for your project using AWS CodePipeline, CodeCommit, and CodeBuild. It automates the deployment process by managing source control and the backend infrastructure.
- AWS CDK installed globally ('npm install -g aws-cdk')
- AWS credentials configured on your machine
- Node.js installed ('npm ci' will run during the build process)
- Git set up for interacting with AWS CodeCommit
First, deploy the AppPipelineStack. This will create an AWS CodeCommit repository where you can push your backend and frontend code, and a CodePipeline that will manage your deployment.
cdk deploy AppPipelineStackThis creates a CodeCommit repository called 'cdkPipelineRepo'. The pipeline will also be set up, but you need to push your code to this repository before the pipeline can run.
After the pipeline has been created, clone the newly created CodeCommit repository and push your backend CDK code.
- Clone the CodeCommit repo:
git clone https://git-codecommit.<region>.amazonaws.com/v1/repos/cdkPipelineRepo- Push your existing AppCdkStack CDK code to the repo:
git add .
git commit -m 'Add AppCdkStack'
git push origin mainThe pipeline will automatically pick up the changes and start deploying the AppCdkStack. You can monitor the deployment stages in the AWS CodePipeline console.
Once the backend has been deployed, a second repository for the frontend will appear in CodeCommit. Repeat the process to push your frontend code to the new repository.
- Clone the frontend repo:
git clone https://git-codecommit.<region>.amazonaws.com/v1/repos/frontendRepo- Add and push your frontend code:
git add .
git commit -m 'Add frontend code'
git push origin mainThe frontend pipeline will automatically deploy your frontend to the specified infrastructure.
The pipeline is defined as follows:
const pipeline = new CodePipeline(this, 'Pipeline', {
pipelineName: 'cdkPipeline',
synth: new CodeBuildStep('SynthStep', {
input: CodePipelineSource.codeCommit(repo, 'main'),
installCommands: ['npm install -g aws-cdk'],
commands: ['npm ci', 'npm run build', 'npx cdk synth']
}),
selfMutation: true
});This ensures that your CDK code is automatically synthesized and deployed whenever new changes are pushed to the CodeCommit repository.
You can monitor the pipeline's progress in the AWS Console under CodePipeline > Pipelines > cdkPipeline. Each stage, from source retrieval to build and deployment, is tracked.