0

I have an RDS SQL instance running, currently it's in Pre-Dev , and I don't want to keep it running all day long. For now I stop and start whenever I need it, Unfortunately it starts (auto) once in 5-7 and keeps running and eating up my credit.

How I can I avoid that ? AWS Lambda function with monitors once in 5-7 days and shutdown whenever it starts ?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • I started working on a CloudFormation stack that takes care of this but never finished. Look for `TODO`. Might save you some time https://gist.github.com/kichik/7a2ecb0d36358c50c7b878ad9fd982bc – kichik Jan 05 '20 at 00:38

2 Answers2

3

From Stopping an Amazon RDS DB Instance Temporarily - Amazon Relational Database Service:

You can stop a DB instance for up to seven days. If you don't manually start your DB instance after seven days, your DB instance is automatically started so that it doesn't fall behind any required maintenance updates.

So, the "auto starting" behaviour is expected.

If you rarely use the database, another option is to Snapshot and Delete the database. Then, when you need it again, you could launch a new database from the Snapshot.

Amazon RDS is not intended to be stopped for long periods.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
0

May be you can subscribe to RDS events. There is an event called "Db Instance started".

So you subscribe a lambda to the event, and the lambda will stop the rds instance (may be if an environment variable called StopRDS set to true)

Note: I haven't tested this on my own.

Reference: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Events.html

Arun Kamalanathan
  • 8,107
  • 4
  • 23
  • 39
  • There is a ready to use code at https://stackoverflow.com/a/48290774/38592 and some newer versions at https://gist.github.com/kichik/7a2ecb0d36358c50c7b878ad9fd982bc. – myroslav Feb 11 '21 at 23:27