Friday, November 28, 2014

AWS Facts: EC2 instance






------------------------------------ aws cli bits ----------------------------------------

##### two columns with listing ID and their names
 aws ec2 describe-instances --output text --filters "Name=instance-state-name,Values=running" --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value[]]' | sed '$!N;s/\n/         /'

 #### getting three columns (just for testing)
 aws ec2 describe-instances --output text --filters "Name=instance-state-name,Values=running" --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value[]]' | sed '$!N;s/\n/     /; $!N;s/\n/      /'


 #### $!N means read in the next line only if it is not the last line in the file. If it would try to read in the line after the last line some versions of sed simply quit without doing anything. That's why you should use $!.
 #### http://askubuntu.com/questions/461191/what-is-the-meaning-of-an-in-a-sed-command

Thursday, November 27, 2014

AWS Facts: SES


  • If you are granted production access, you no longer have to verify "To" addresses or domains; however, you must still verify any additional "From" or "Return-Path" addresses or domains. 


  • sandbox: You can send a maximum of 200 messages per 24-hour period.

AWS Facts: Route53

A) ALIAS records:

  • An ALIAS record will link your record set to a particular AWS resource directly (i.e. you can map a domain to an S3 bucket, ELB, CloudFront distribution) 
  • You can create an alias resource record set at the zone apex. For example, if you register the DNS name example.com, the zone apex is example.com.
      • if you try to set CNAME or A record of some apex zone(e.g. example.com), it will give you error. So the only option is just to make an alias entry. 
  • Amazon Route 53 doesn't charge for alias queries, however charges for CNAME queries. 




------------------------------------ aws cli bits ----------------------------------------
### List all the hosted zones
$ for i in `aws route53 list-hosted-zones --output=text --profile myprofile --query 'HostedZones[*].Name'`; do echo "$i"; done

### List all the records against Z2A22EOFF20PZ7 hostedzone.
    $ aws route53 list-resource-record-sets --hosted-zone-id "/hostedzone/Z2A22EOFF20PZ7" --profile myprofile

Monday, November 17, 2014

AutoScaling: how to deploy code using autoscaling

Environment:
    Autoscaling limit: 3
  • Release your code by taking the reference of some AMI.
  • Post deployment, cut an AMI and create new Launch Configuration(e.g. product-141117).
  • Take a snapshot of already running Instance.
  • Change the launch configuration of particular Autoscaling Group by updating the AMI id.
  • Now 'scale up' instance limit in "AutoScaling Group" from 3 to 6.
  • De-select the old instances(3) from ELB.
  • Test website.
  • Scale down autoscaling group from 6 to 3.
  • remove old launch configuration.

Note: Here point 8) is tricky one, how does Autoscaling know which EC2 instance to terminate?
   - Actually AutoScaling is built in such a way that when one scales it down, the system terminates the EC2 instance by "oldest-first" rule. That means the old EC2 instances get terminated.