This AWS CDK (Cloud Development Kit) project provides infrastructure automation for deploying Django deploy CI/CD project on AWS.
Before getting started with this project, ensure that you have the following prerequisites:
- AWS CLI (https://aws.amazon.com/cli/)
- AWS CDK (https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_install)
- Node.js (https://nodejs.org/en/download/)
Follow these steps to set up and deploy the infrastructure:
- Clone this repository to your local machine:
git clone https://github.com/ndhoanit1112/django-cicd-aws-cdk
cd django-cicd-aws-cdk
-
Modify some environment variables in the
env
folder:Open
env/dev.yml
andenv/prod.yml
files
- Update the
connectionArn
variable with the appropriate connection ARN. - Update the
keyName
variable with the name of your key pair to access the bastion host (create a keypair in AWS Console incase you don't have a key pair yet). - Update the
region
variable with the AWS region where you want to deploy the stacks.
- Install project dependencies:
npm install
- Configure your AWS credentials using the AWS CLI:
aws configure
- Synthesizes AWS CloudFormation templates:
npx aws-cdk synth --all
- Deploy the infrastructure stacks to AWS:
npx aws-cdk deploy --all
This command will deploy all the stacks defined in the project.
- Note: If you want to deploy to the production environment, add the DEPLOY_ENV=prod environment variable to your deployment command. For example:
DEPLOY_ENV=prod npx aws-cdk deploy --all
This project creates the following AWS resources:
- VPC Stack: Establishes a Virtual Private Cloud (VPC) with public and private subnets, routing tables, and internet gateway for network isolation and security.
- Secrets Manager Stack: Sets up AWS Secrets Manager to securely store sensitive information like database credentials.
- ECR Stack: Sets up the Elastic Container Registry (ECR) to store Docker container images for the Django application.
- ECS Stack: Creates an Elastic Container Service (ECS) cluster and task definitions for running the Django application as a containerized service.
- ELB Stack: Configures an Application Load Balancer (ALB) to distribute incoming traffic across the ECS service.
- RDS Stack: Deploys an Amazon RDS database instance to store the application's data.
- SQS Stack: Creates an Amazon Simple Queue Service (SQS) queue for handling background tasks or message processing. In this project, it is used to perform calculations of Fibonacci numbers as a background task.
- Cache Stack: Sets up a Memcached cluster to store and retrieve calculated Fibonacci numbers, reducing the need to recalculate them repeatedly.
- Pipeline Stack: Configures an AWS CodePipeline to automate the deployment process, triggering builds and deployments on every code change.
- EFS Stack: Sets up a shared file system between ECS tasks (This stack doesn't support the funtionality of the application, it is for study/experimental purpose).
To remove the deployed infrastructure from your AWS account, run the following command:
npx aws-cdk destroy --all
This command will delete all the stacks created by the AWS CDK project.