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

#PowerShell: Register AWS EC2 instances in Amazon Route53 (new way)

Amazon Route 53 is a highly available and scalable Domain Name System (DNS) web service.
Just in case – Amazon EC2
I use this script https://github.com/konstantinvlasenko/cloud/blob/master/Register-CNAME.ps1 to provide meaningful names for them.
Simple usage:

$config = @{ DomainName = 'mylab.com' }
$name = "www.$($config.DomainName)"
# get instances
$instance = (Get-EC2Instance $InstanceId).RunningInstance
# update R53
.\Register-CNAME.ps1 $config $name $instance.PublicIpAddress

Advanced usage (register in another account; registering A record):

$config = @{ DomainName = 'mylab.com'; AssumeRoles = @{ R53 = @{ ARN = 'arn:aws:iam::600021112340:role/Route53'; SessionName = 'Friends' } }; }
$name = "www.$($config.DomainName)"
# get instances
$instance = (Get-EC2Instance $InstanceId).RunningInstance
# update R53
.\Register-CNAME.ps1 $config $name $instance.PublicIpAddress 'A'

Apply GeoTrust certificate to AWS ELB

Here is the tool which I used to verify correctness of my AWS ELB SSL configuration.

AWS ELB

  • Certificate Name – put here whatever you want
  • Private Key – copy and past content of server.key file
  • Public Key Certificate – copy and paste content of your_site_name_ee.cer file

This will be enough to pass validation by the tool. But you will get one warning. Because GeoTrust  is quite new player on the market. Old browser doesn’t have information about GeoTrust. So GeoTrust provides intermediate certificates. You need to set Certificate Chain field if you care about old browsers.

  • Certificate Chain – copy and paste content of GeoTrust Extended Validation SSL CA – G2.txt and then copy and paste content of GeoTrust Primary Certification Authority.txt

 

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