https://github.com/theuves/docdb-autoscaling
An auto-scaling solution for Amazon DocumentDB.
https://github.com/theuves/docdb-autoscaling
amazon-web-services autoscaling aws aws-lambda terraform terraform-modules
Last synced: 6 months ago
JSON representation
An auto-scaling solution for Amazon DocumentDB.
- Host: GitHub
- URL: https://github.com/theuves/docdb-autoscaling
- Owner: theuves
- License: mit
- Created: 2021-08-26T01:53:01.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-10-13T21:07:46.000Z (almost 3 years ago)
- Last Synced: 2025-04-05T22:30:00.545Z (6 months ago)
- Topics: amazon-web-services, autoscaling, aws, aws-lambda, terraform, terraform-modules
- Language: Python
- Homepage:
- Size: 82 KB
- Stars: 10
- Watchers: 0
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docdb-autoscaling
[](https://github.com/theuves/docdb-autoscaling/actions/workflows/terraform.yml)
[](https://github.com/theuves/docdb-autoscaling/blob/master/LICENSE)An auto-scaling solution for Amazon DocumentDB.
This project is an [AWS Lambda](https://aws.amazon.com/lambda/) written in Python and deployed with [Terraform](https://www.terraform.io/) that easily implements auto-scaling functionality for [Amazon DocumentDB](https://aws.amazon.com/documentdb/).
## Why?
Amazon DocumentDB (with MongoDB compatibility) supports [up to 15 read replicas](https://docs.aws.amazon.com/documentdb/latest/developerguide/replication.html), but by default AWS does not provide an easy way to set up an auto-scaling policy for them.
## The solution
Follow below how the system works:

Resources created by Terraform:
- **[CloudWatch](https://aws.amazon.com/cloudwatch/) alarm** ─ will watch a CloudWatch metric from the Document Database cluster (e.g. `CPUUtilization`).
- **[Simple Notification Service (SNS)](https://aws.amazon.com/sns/)** ─ will be triggered by CloudWatch when any metrics are matched.
- **[AWS Lambda](https://aws.amazon.com/lambda/)** ─ will be triggered by the SNS and will be responsible for adding or removing read replicas in the Document Database cluster.## Terraform module
You can deploy the function with Terraform using the following syntax:
```terraform
module "docdb-autoscaling-prod" {
source = "github.com/theuves/docdb-autoscaling"
cluster_identifier = "my-prod-cluster"
name = "docdb-autoscaling-prod"
min_capacity = 3
max_capacity = 6scaling_policy = [
{
metric_name = "CPUUtilization"
target = 80
statistic = "Average"
cooldown = 300
}
]
}
```## Deployment
To create the resources:
```bash
terraform init
terraform plan
terraform apply
```To destroy:
```bash
terraform destroy
```## Input variables
| Variable | Description | Type | Default value |
|:---|:---|:---|:---|
| `cluster_identifier` | DocumentDB cluster identifier. | `string` | n/a |
| `name` | Resources name. | `string` | `"docdb-autoscaling"` |
| `min_capacity` | The minimum capacity. | `number` | `0` |
| `max_capacity` | The maximum capacity. | `number` | `15` |
| `scaling_policy` | The auto-scaling policy. | [see here](#scaling_policy) | [see here](#scaling_policy) |### `scaling_policy`
Type:
```terraform
list(object({
metric_name = string
target = number
statistic = string
cooldown = number
}))
```Default value:
```terraform
[
{
metric_name = "CPUUtilization"
target = 60
statistic = "Average"
cooldown = 120
}
]
```Options:
- `metric_name` ─ Amazon DocumentDB metric name ([see the list](https://docs.aws.amazon.com/documentdb/latest/developerguide/cloud_watch.html)).
- `target` ─ The value against which the specified statistic is compared.
- `statistic` ─ The statistic to apply to the alarm's associated metric (supported values: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum`).
- `cooldown` ─ The cooldown period between scaling actions.## Output values
n/a
## License
MIT