Sub topic 16
Controlling cost and cleaning up
This chapter assumes you have created the demo-pg instance from the earlier chapters and know the AWS CLI. It covers what RDS charges for, how to reduce those charges, and how to delete test resources safely.
What you pay for
An RDS bill has several parts. Each one keeps running until you remove the resource behind it.
| Cost item | Billed when | Common surprise |
|---|---|---|
| Instance hours | The instance is running | A Multi-AZ deployment bills for the standby too |
| Storage (GiB-month) | Storage is allocated | You pay for allocated size, not used size |
| Provisioned IOPS or throughput | Configured above the gp3 baseline | Stays on until you change it |
| Backup storage | Manual snapshots exist, or automated backups exceed your allocated storage | Manual snapshots remain after the instance is deleted |
| Read replicas | Each replica runs | Each replica is a full instance |
| Data transfer | Data leaves the Region or crosses AZs | Cross-Region replicas add transfer charges |
Check current prices for your Region on the RDS pricing page, because they change.
Ways to reduce cost
- Right-size the instance. Look at CPU and
FreeableMemoryin CloudWatch. If CPU stays low, move to a smaller class. - Skip Multi-AZ outside production. Development and test databases rarely need a standby.
- Shorten backup retention. Use
--backup-retention-period 1for test systems. - Stop idle instances. A stopped instance does not bill for instance hours, but storage and backups still bill.
- Buy Reserved Instances for steady production databases that will run for a year or more.
Stop and start an instance with the CLI:
aws rds stop-db-instance --db-instance-identifier demo-pg
aws rds start-db-instance --db-instance-identifier demo-pgYou cannot stop an instance that has read replicas, and some Multi-AZ configurations have restrictions depending on the engine.
Deleting test resources
Deleting an instance does not delete everything that was created around it. Use this order:
- Delete read replicas first.
- Delete the instance.
- Delete manual snapshots you no longer need.
- Delete custom parameter groups and the DB subnet group.
The test restore from the backups chapter is a throwaway instance. Delete it without a final snapshot:
aws rds delete-db-instance \
--db-instance-identifier demo-pg-restored \
--skip-final-snapshotFor an instance you might want back, take a final snapshot instead:
aws rds delete-db-instance \
--db-instance-identifier demo-pg \
--final-db-snapshot-identifier demo-pg-finalRemove the remaining pieces:
aws rds delete-db-parameter-group --db-parameter-group-name demo-pg16
aws rds delete-db-subnet-group --db-subnet-group-name demo-subnetsParameter group deletion fails while an instance still uses it, so delete instances first. If the instance used --manage-master-user-password, RDS removes the managed secret when the instance is deleted.
Finding forgotten resources
List instances and manual snapshots to see what is still billing:
aws rds describe-db-instances \
--query "DBInstances[].[DBInstanceIdentifier,DBInstanceStatus,DBInstanceClass]" \
--output table
aws rds describe-db-snapshots --snapshot-type manual \
--query "DBSnapshots[].[DBSnapshotIdentifier,AllocatedStorage]" \
--output tableRun these in every Region you have used. Add a budget alert in AWS Budgets so an unexpected charge sends you an email.
Exercise
You stopped a test instance on Monday and did not look at it again. Name two charges that continued during the week, and one event that happens after seven days.
Show answer
Storage and backup storage kept billing while the instance was stopped. After seven days RDS starts the instance automatically, so instance hours bill again.