Jimmy
Jimmy

Reputation: 12517

Amazon RDS - Online only when needed?

I had a question about Amazon RDS. I only need the database online for about 2 hours a day but I am dealing with quite a large database at around 1gb.

I have two main questions:

  1. Can I automate bringing my RDS database online and offline via scripts to save money?

  2. When I put a RDS offline to stop the "work hours" counter running and billing me, when I bring it back online will it still have the same content (i.e will all my data stay there, or will it have to be a blank DB?). If so, is there any way around this rather than backing up to S3 and reimporting it every time?

Upvotes: 42

Views: 23049

Answers (4)

Richard Hurt
Richard Hurt

Reputation: 2078

Amazon recently updated their CLI to include a way to start and stop RDS instances. stop-db-instance and start-db-instance detail the steps needed to perform these operations.

Upvotes: 7

kevin
kevin

Reputation: 114

Here's a script that will stop/start/reboot an RDS instance

#!/bin/bash

# usage ./startStop.sh lhdevices start

INSTANCE="$1"
ACTION="$2"



# export vars to run RDS CLI
export JAVA_HOME=/usr;
export AWS_RDS_HOME=/home/mysql/RDSCli-1.15.001;
export PATH=$PATH:/home/mysql/RDSCli-1.15.001/bin;
export EC2_REGION=us-east-1;
export AWS_CREDENTIAL_FILE=/home/mysql/RDSCli-1.15.001/keysLightaria.txt;

if [ $# -ne 2 ]
then
echo "Usage: $0 {MySQL-Instance Name} {Action either start, stop or reboot}"
echo ""
exit 1
fi


shopt -s nocasematch

if [[ $ACTION == 'start' ]]
then
echo "This will $ACTION a MySQL Instance"  
rds-restore-db-instance-from-db-snapshot lhdevices 
--db-snapshot-identifier        dbStart --availability-zone us-east-1a     
--db-instance-class db.m1.small 

echo "Sleeping while instance is created"
sleep 10m
echo "waking..."

rds-modify-db-instance lhdevices --db-security-groups kfarrell

echo "Sleeping while instance is modified for security group name"
sleep 5m
echo "waking..."

elif [[ $ACTION == 'stop' ]]
then
echo "This will $ACTION a MySQL Instance" 

yes | rds-delete-db-snapshot dbStart

echo "Sleeping while deleting old snapshot "
sleep 10m

#rds-create-db-snapshot lhdevices --db-snapshot-identifier dbStart

# echo "Sleeping while creating new snapshot "
# sleep 10m
# echo "waking...."

#rds-delete-db-instance lhdevices --force --skip-final-snapshot 
rds-delete-db-instance lhdevices --force --final-db-snapshot-identifier dbStart

echo "Sleeping while instance is deleted"
sleep 10m
echo "waking...."

elif [[ $ACTION == 'reboot' ]]
then
echo "This will $ACTION a MySQL Instance" 
rds-reboot-db-instance lhdevices ;

echo "Sleeping while Instance is rebooted"
sleep 5m
echo "waking...."

else

echo "Did not recognize command: $ACTION"
echo "Usage: $0 {MySQL-Instance Name} {Action either start, stop or reboot}"

fi
shopt -u nocasematch

Upvotes: 9

BestPractices
BestPractices

Reputation: 12876

If you wish to do this programatically,

  1. Snapshot the RDS instance using rds-create-db-snapshot http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-CopyDBSnapshot.html

  2. Delete the running instance using rds-delete-db-instance http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-DeleteDBInstance.html

  3. Restore the database from the snapshot using rds-restore-db-instance-from-db-snapshot http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-RestoreDBInstanceFromDBSnapshot.html

You may also do all of this from the AWS Web Console as well, if you wish to do this manually.

Upvotes: 30

Thibault D.
Thibault D.

Reputation: 10004

You can start EC2* instances using shell scripts, so I guess that you can as well for RDS. (see http://docs.aws.amazon.com/AmazonRDS....html)

But unlike EC2*, you cannot "stop" an RDS instance without "destroying" it. You need to create a DB snapshot when terminating your database. You will use this DB snapshot when re-starting the database.

*EC2 : Elastic Computing, renting a virtual server or a server.

Upvotes: 10

Related Questions