How to stop RDS and Aurora databases automatically in dev and staging
Short answer: A dev or staging database on Amazon RDS, Aurora or DocumentDB keeps billing instance hours after the application servers stop. AWS can stop it, but only for seven days at a time, and a schedule cannot tell whether anyone needs it. With Idlefy, the database belongs to a leased environment: it stays stopped, starts when a person leases the environment, and stops again when nobody holds a lease.
Why does a stopped dev environment still cost money?
A stopped dev environment still costs money when its database keeps running. Teams usually automate the virtual machines (VMs) first, because stopping an EC2 instance is one call. The database is a separate AWS service with its own start and stop calls, so it often stays up through nights and weekends while the servers that use it are off. A running RDS instance, Aurora cluster or DocumentDB cluster bills instance hours whether or not anything connects to it. A staging database also never looks unused by itself: the application keeps its connections open for as long as the application runs. That is why the useful unit to stop is the whole environment, application and database together, and not the database alone.
Can you stop an RDS, Aurora or DocumentDB database, and what keeps billing?
Yes, AWS can stop an RDS instance, an Aurora cluster and a DocumentDB cluster, and a stop keeps the data, the endpoint and the configuration. While the database is stopped, AWS does not bill its instance hours. Storage, Provisioned IOPS and backups stay billed, and so does the public IPv4 address of a publicly accessible RDS instance. Two limits come from AWS itself:
- Seven days. AWS starts a stopped database again by itself after seven days. Anything that stops databases has to stop them again after that.
- Some databases cannot be stopped. AWS does not stop an RDS instance that has a read replica or is one, an RDS for SQL Server instance in a Multi-AZ deployment, an Aurora cluster that has a cross-Region read replica or is part of a blue/green deployment, or an Aurora cluster in a global database unless it is the only cluster there.
Idlefy itself does not stop a few more: it marks every Aurora cluster in a global database as not stoppable, even the only one, and also an Aurora cluster that replicates from another cluster, a Multi-AZ DB cluster and Aurora Serverless v1.
Starting a database is slower than starting a VM. It takes minutes, and sometimes much longer.
What are the do-it-yourself ways to stop a database on a schedule?
| Method | Starts when a person needs it | Handles the seven-day restart | Starts the database before the application | Nothing to build or run |
|---|---|---|---|---|
| Idlefy leased environment | Yes | Yes | Yes | Yes |
| EventBridge Scheduler or a Lambda function | No | If you build it | If you build it | No |
| Instance Scheduler on AWS | No | If you configure it | No | No |
EventBridge Scheduler or a Lambda function. A schedule calls StopDBInstance or StopDBCluster in the evening and the start call in the morning. It is cheap and it works for a team with fixed hours. You write and maintain it: one more schedule per database, an IAM role, error handling for a database that is busy with a backup or a change when the call arrives, and an order of operations if the application must start after the database.
Instance Scheduler on AWS. The AWS solution deploys with CloudFormation and stops and starts tagged EC2 and RDS resources by schedules you define. Your team owns that stack and its updates.
Both answer “what time is it”. Neither answers “does anyone need this environment now”. A schedule keeps the database running through every working hour, used or not, including holidays and the week the team works on something else. It also turns the database off under the person who works late or in another time zone, and that person then needs AWS console access or a teammate to bring it back.
How does Idlefy stop a dev or staging database automatically?
Idlefy treats the database as part of a leased environment. A Smart Workflow is a shared dev or staging environment that people book for a set time: the lease fires your own CI pipeline (GitHub Actions or GitLab CI) to bring the environment up, and the end of the lease fires the teardown pipeline. A Smart Workflow on AWS can now also hold a list of databases: RDS instances, Aurora clusters and DocumentDB clusters. The flow:
- The databases on the list stay stopped while nobody leases the environment.
- A person leases the environment for a set time, from the web dashboard, from Slack or Telegram on paid plans, or through an AI agent.
- Idlefy starts the databases in the order of the list and waits for each one to be available before it starts the next.
- When every database is up, the start pipeline runs, if the workflow has one, and the environment becomes active.
- Several people can join the same lease, and it can be extended.
- When the lease ends or is released, the teardown pipeline runs first, and then Idlefy stops the databases in reverse order.
A database on the list is off by default. If it is found running while nobody leases the environment, because AWS restarted it after seven days or someone started it in the console, Idlefy stops it. Idlefy sends no message for such a stop; it is recorded in the Activity Log.
The time a database takes to start is part of the booked time, so book a little longer than the work needs.
What does Idlefy need in AWS to start and stop a database?
Idlefy needs two things: a tag on the database and the permissions of the current Idlefy CloudFormation template.
The tag. AWS checks the idlefy=enabled tag for start and stop, and only a tagged database can be added to a workflow; Idlefy manages only the supported databases an owner attaches to a Smart Workflow. For Aurora and DocumentDB the tag goes on the cluster. Anyone in your AWS account who can tag a database lets the role start and stop it this way, so limit who may add that tag if this matters to you.
The permissions. An AWS connection made with an earlier version of the Idlefy template has no database permissions. The owner does this once: Update the Idlefy CloudFormation stack, or grant the database permissions in your manually managed AWS role. A stack update changes the role’s policy in place and replaces nothing. A connection that is not updated keeps working for EC2. With the current template the role can:
- read the configuration and tags of the databases in the account (
rds:DescribeDBInstances,rds:DescribeDBClusters,rds:ListTagsForResource). AWS cannot limit the two describe calls by tag, so this read covers every database the RDS API lists in the account, tagged or not; - start and stop a database (
rds:StartDBInstance,rds:StopDBInstance,rds:StartDBCluster,rds:StopDBCluster) only when it carries the tag. On AWS that boundary is enforced by the IAM policy itself.
The read covers every database the RDS API lists in the account, Neptune included. Neptune uses the same start and stop calls, so a Neptune cluster tagged the same way could also be started and stopped by the role, although Idlefy lists and manages only RDS, Aurora and DocumentDB.
Idlefy does not access database contents and does not retrieve database passwords. The role has no database login and no access to Secrets Manager. The default policy grants no create, delete, resize or modify actions for databases. Idlefy starts and stops databases without requesting snapshots or changes to capacity reservations, and never connects to a database. No agent is installed in the database, on the account’s machines or in a Kubernetes cluster: Idlefy calls the AWS API through the role its CloudFormation stack creates.
How do you set it up?
An organization owner does this once per environment:
- Connect the AWS account in Idlefy, by default without access keys. For an existing connection, update the Idlefy CloudFormation stack, or grant the database permissions in your manually managed AWS role.
- Tag each dev or staging database with
idlefy=enabled. - Open the Smart Workflow for the environment, find the tagged databases and add them to the workflow in the order they should start. A workflow holds up to five.
- If a database is running when you add it, confirm that Idlefy may stop it: from then on it runs only while someone leases the environment.
- Give your team access to the workflow.
Anyone who may lease the workflow can then start and stop its databases through a lease. Only an organization owner can change the list, and not while the environment is in use. A database can belong to one workflow at a time.
What are the limits?
- AWS only. Databases in Smart Workflows work on AWS. Google Cloud databases are not managed.
- Three kinds. RDS instances, Aurora clusters and DocumentDB clusters. Caches, search clusters and message queues stay steps in your own pipeline, and so does Kubernetes: Idlefy does not talk to a cluster.
- Databases Idlefy does not stop. The ones Idlefy marks as not stoppable, listed above, cannot be added, including Aurora Serverless v1 and Multi-AZ DB clusters.
- Aurora Serverless v2 that pauses by itself. A cluster set to scale to zero can pause by itself when nothing is connected, so adding it to a workflow saves little and makes the start slower.
- A lease, not a schedule. There is no timetable, and a database cannot be leased by itself outside a workflow.
- Stopped is not free. Storage, Provisioned IOPS and backups stay billed by AWS, and so does the public IPv4 address of a publicly accessible RDS instance.
- Pending maintenance. On RDS and Aurora a stop removes scheduled maintenance actions, except parameter group and option group changes, so after a start check the database’s pending maintenance and reapply what you want. DocumentDB applies scheduled maintenance after the next start.
- A failed start. If a database does not come up, the lease is marked failed, and the person can retry, start the environment anyway or cancel.
- Removing a database. When you remove a running database from a workflow, or delete the workflow, Idlefy stops that database once and then leaves it alone.
- Production. Keep a database that has to serve customers around the clock out of this model.
Frequently asked questions
Does stopping an RDS database delete data? No. A stop keeps the data, the endpoint and the configuration. Idlefy requests no snapshot and deletes nothing.
Why does my stopped RDS database start again by itself? AWS starts a stopped database after seven days. When that happens to a database in an Idlefy workflow and nobody leases the environment, Idlefy stops it again.
Can Idlefy read the data in my database? No. Idlefy never connects to a database, does not access database contents and does not retrieve database passwords. Its role has no database login; it reads the configuration and tags that the AWS API reports.
Do databases in a Smart Workflow cost extra in Idlefy? No. Databases are included in the workflow, with no separate charge. Plans are on the pricing page. AWS bills the database itself to your account as before.
Do I need to install an agent? No. Idlefy starts and stops databases through the AWS API, with the IAM role its CloudFormation stack creates in your account. No agent is installed in the database, on your machines or in a Kubernetes cluster.
Can I stop an Aurora Serverless database this way? Aurora Serverless v1 cannot be stopped by AWS. An Aurora Serverless v2 cluster can be added like any other Aurora cluster, but one that pauses by itself gains little.
Will Idlefy stop a database I did not tag?
No. Without the enabling tag (idlefy=enabled, with the key in either letter case) the IAM policy refuses the start and the stop.
Can I keep my existing schedule for the same database? Pick one or the other. If a schedule starts a database every morning while nobody leases the environment, Idlefy stops it again.
Disclosure
I’m the founder of Idlefy, so this describes our own product and favors it. The lease lifecycle is on the how it works page.
Related reading: How to stop EC2 instances automatically for the machines next to the database, auto-shutdown for dev and staging environments, and The $5,000 weekend on what a forgotten environment costs.