Amazon RDS Now Supports T2 Instances

That is good news.

T2 instances CPU credits is really great feature introduced 2 months ago for EC2. Amazon RDS Now Supports T2 Instances

At the same time the price for T2 RDS instances is twice less then for the previous generation.

T2.micro EC2 + T2.micro RDS are good if you are thinking about web app which will have the “scheduled” workload. E.g. the main customers are from the particular region.

While the instance is IDLE it accumulate CPU credits. And you servers will be able to burst above the baseline as needed. You can track your CPU Credits trough AWS Console. It is really fun to track them

On the image below one of my EC2 instance has 150 CPU Credits. This means that it will be able to rocket up to the “cloud”  if needed. But still you pay for micro instance. CPU Credits really brilliant idea from Amazon!


CPUCredits

Backup you on-prem/local #PostgreSQL database to cloud #AWS #RDS snapshot

backup for $0.026 + $0.125 per GB-month

Total costs of the backup operation: $0.026 + $0.125 per GB-month

Script below will do the following steps:

  1. create PostgresSQL AWS RDS t1.micro instance
  2. wait till instance started by using aws rds describe-db-instances
  3. get AWS RDS instance address
  4. copy database
  5. create AWS RDS instance snapshot and terminate instance by using aws rds delete-db-instance
  6. send notification by using AWS SNS service

Prerequisites:

#!/bin/bash
SNSTOPIC=arn:aws:sns:us-east-1:000000000000:MYTOPIC
RDSINSTANCE=MYBACKUP
_now=$(date +"%d%m%Y")
BACKUPNAME="$RDSINSTANCE$_now"
DATABASE=MYDB
DBADMIN=admin
export PGPASSWORD=MYPASSWORD

# create RDS instance
aws rds create-db-instance --db-instance-identifier $RDSINSTANCE --allocated-storage 5 --db-instance-class db.t1.micro --no-multi-az --engine postgres --master-username $DBADMIN --master-user-password $PGPASSWORD --db-name $DATABASE --backup-retention-period 0

# wait till instance started
while [ `aws rds describe-db-instances --db-instance-identifier $RDSINSTANCE | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["DBInstances"][0]["DBInstanceStatus"]'` != "available" ]; do sleep 10; done

# get instance address
AWSHOST=`aws rds describe-db-instances --db-instance-identifier $RDSINSTANCE | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["DBInstances"][0]["Endpoint"]["Address"]'`

# copy database
pg_dump -U postgres dbname=$DATABASE | psql --host=$AWSHOST --username=$DBADMIN --dbname=$DATABASE

# terminate instance and create snapshot
aws rds delete-db-instance --db-instance-identifier $RDSINSTANCE --final-db-snapshot-identifier $BACKUPNAME

# send notification
aws sns publish --topic-arn $SNSTOPIC --subject 'AWS RDS BACKUP' --message 'Done'

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:)