Restore #AWS RDS instance from a database snapshot by using AWS CLI

The AWS Command Line Interface is a unified tool to manage your AWS services.
I am using AWS RDS PostgreSQL for my application. I don’t need to run this application 24/7/365. So I have the ability to stop periodically my instances to save some money in my pocket. Nobody wants to do repeated tasks manually. So am I.
Below is the bash script which I use to restore db instance from a snapshot and wait till availability status:

aws rds restore-db-instance-from-db-snapshot --db-instance-identifier myDBinstanseName --db-snapshot-identifier myDBinstanseName-final-snapshot --db-instance-class db.t1.micro --no-multi-az
while [ `aws rds describe-db-instances --db-instance-identifier myDBinstanseName| python -c 'import json,sys;obj=json.load(sys.stdin);print obj["DBInstances"][0]["DBInstanceStatus"]'` != "available" ]; do sleep 10; done

Note: This script is part of bigger automation. So I don’t run it manually:)

One thought on “Restore #AWS RDS instance from a database snapshot by using AWS CLI

  1. This is very attention-grabbing, You are an overly skilled blogger.
    I have joined your rss feed and sit up for looking for extra
    of your excellent post. Additionally, I have shared your
    web site in my social networks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s