This project provides an automated solution for provisioning RDS clusters on AWS using a Serverless architecture and Infrastructure as Code.
- API Gateway: Entry point for provisioning requests.
- SNS & SQS: Decouples the request from processing, ensuring reliability.
- Lambda: Consumes messages, generates Terraform code, and creates a GitHub Pull Request.
- Terraform: Defines the RDS infrastructure.
- CircleCI: Orchestrates the deployment of the serverless stack and the application of Terraform changes.
- AWS Account
- GitHub Account & Personal Access Token (PAT) with
reposcope. - CircleCI Account linked to GitHub.
- AWS Credentials configured in CircleCI (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION).
- GitHub PAT stored in AWS Secrets Manager (Secret Name:
github/patby default).
- Fork/Clone this repository.
- Store your GitHub PAT in AWS Secrets Manager:
aws secretsmanager create-secret --name github/pat --secret-string "YOUR_GITHUB_TOKEN". - Push the code to GitHub.
- Set up the project in CircleCI.
The deploy-serverless job in CircleCI will automatically deploy the API Gateway, Lambda, SNS, and SQS stack when you push to main.
Alternatively, you can deploy manually using AWS SAM:
sam build
sam deploy --guidedTo provision a new RDS cluster, send a POST request to the API Gateway endpoint (outputted by the SAM deployment).
Endpoint: https://<api-id>.execute-api.<region>.amazonaws.com/Prod/provision
Payload:
{
"db_name": "my-app-db",
"engine": "mysql",
"environment": "dev"
}- The request is queued in SQS.
- The Lambda function picks it up.
- A new branch
feature/provision-rds-my-app-dbis created in this repo. - A Terraform file
terraform/live/my-app-db.tfis added. - A Pull Request is opened against
main. - CircleCI runs
terraform planon the PR. - Once you merge the PR, CircleCI runs
terraform applyto create the RDS database.
lambda/: Python source code for the Lambda function.terraform/modules/rds/: Terraform module for the RDS cluster.template.yaml: AWS SAM template..circleci/: CI/CD configuration.
