This is a stable example. It should successfully build out of the box
This example is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build.
This AWS Cloud Development Kit (CDK) Python example demonstrates how to configure AWS CodePipeline with CodeCommit, CodeBuild, and CodeDeploy to build and deploy a Docker image to an Elastic Container Service (ECS) cluster running AWS Fargate (serverless compute for containers).
When working in fast-paced development environments, CI/CD (Continuous Integration and Continuous Delivery) pipelines are used to automatically build, test, and deploy application changes across multiple accounts and environments. This allows new features and bug fixes to be tested and deployed quickly to continuously improve the application.
- CodePipeline
- CodeCommit
- CodeBuild
- CodeDeploy
- Elastic Container Service (ECS)
- Fargate
- Elastic Container Registry (ECR)
- Lambda
- Authenticate to an AWS account via a Command Line Interface (CLI).
- Navigate to this
codepipeline-build-deploydirectory. pip install -r requirements.txtto install the required dependencies.cdk synthto generate and review the CloudFormation template.cdk diffto compare local changes with what is currently deployed.pytestto run the unit tests we specify intests/unit/test_codepipeline_build_deploy_stack.py.cdk deployto deploy the stack to the AWS account you're authenticated to.
After a successful deployment, CDK will output a public endpoint for:
- Application Load Balancer (ALB)
- To test that the Docker image was built and deployed successfully to ECS, we can use the Application Load Balancer (ALB) public endpoint, e.g.
http://xyz123.us-east-1.elb.amazonaws.com. - The simple containerized application contains multiple pages for testing:
/index.html/about.html/contact.html/error.html
- To run the Python unit tests, execute the following commands:
pip install -r requirements-dev.txtpytest
- Navigate to the AWS CodePipeline console and select
ImageBuildDeployPipeline. Then click onRelease changeto trigger the pipeline and observe the workflow in action end-to-end. - Navigate to the AWS Console to view the services that were deployed:
- CodePipeline pipeline
- CodeCommit repository
- CodeBuild project
- CodeDeploy application
- ECS cluster
- ECS service on Fargate
- ECR image repository
- Lambda functions
- Add manual approval actions to the CodePipeline workflow.
- Deploy to multiple accounts with CodeDeploy.
- Set up Elastic Container Registry (ECR) repository cross-account or cross-region replication.
- Protect the public Application Load Balancer (ALB) from attacks and malicious traffic using Web Application Firewall (WAF).
- Enable SSL/TLS at the Application Load Balancer (ALB) using AWS Certificate Manager.
- Set up a Route 53 domain to route traffic to an Application Load Balancer (ALB).