Showing posts with label automation. Show all posts
Showing posts with label automation. Show all posts

Friday, December 2, 2016

More things from AWS CLI

Exporting RDS Parameter Groups

aws rds --profile aws_profile describe-db-parameters --db-parameter-group-name paramter_group_name

Creating a Read-Replica of an RDS instance


aws rds create-db-instance-read-replica --db-instance-identifier $UPGRADE_TARGET --source-db-instance-identifier $SOURCE_INSTANCE --profile $AWS_PROFILE

Upgrade an RDS instance


aws rds modify-db-instance --db-instance-identifier $UPGRADE_TARGET --engine-version $UPGRADE_VERSION --profile $AWS_PROFILE --allow-major-version-upgrade --apply-immediately

Promote a Read-Replica


aws rds promote-read-replica --db-instance-identifier $UPGRADE_TARGET --profile $AWS_PROFILE

Rename an RDS instance


aws rds modify-db-instance --db-instance-identifier $SOURCE_INSTANCE --new-db-instance-identifier $SOURCE_SAVE_NAME --apply-immediately --profile $AWS_PROFILE

Enable Multi-AZ on an instance


aws rds modify-db-instance --db-instance-identifier $UPGRADE_TARGET --multi-az --apply-immediately --profile $AWS_PROFILE

Finding IPs in a Subnet

aws ec2 describe-network-interfaces --filters "Name=subnet-id,Values=subnet-subnetid" --region region_name

Thursday, June 9, 2016

Finding stuff in aws cli

TL;DR

Finding default routes: aws ec2 describe-route-tables --query "RouteTables[*].Routes[?DestinationCidrBlock==\`0.0.0.0/0\`]"
Finding Routes that terminate in instances: aws ec2 describe-route-tables --query "RouteTables[*].Routes[?DestinationCidrBlock==\`0.0.0.0/0\`].{Destination:DestinationCidrBlock, Instance:InstanceId, State:State}"
Finding the VPC name for a route that terminates on an instance: 
aws ec2 describe-vpcs --vpc-ids $(aws ec2 describe-route-tables  | 
     jq '.RouteTables[] |  { VpcId, Instance: .Routes[] | 
       select( .InstanceId != null)  }' | 
     jq '.VpcId' | sed 's/\"//g')  |
     jq '.Vpcs[] |
       { VpcId, Name: .Tags[] |
       select ( .Key == "Name") }'
Finding the newest snapshot
aws --profile=prod ec2 describe-snapshots --filter 'Name=volume-id,Values=vol-1c6e8b1a' | jq '.[]|max_by(.StartTime)|.SnapshotId'

Find out how many 0b files in an s3 bucket


aws s3 ls --recursive s3://<folder_name> | awk '{if ($3 == 0) print}'


Background
In my new gig, I'm learning lots more AWS, so I'll be sharing some AWS love here now. The last few weeks, I have been replacing NAT instances with NAT Gateways. It is a great way for your VPC VM's to get to the internet without having to manage a VM.

Well, I thought I was done so I decided to find a way to audit my assumptions. Well, I was wrong. The TL;DR above shows what it took to find the default routes that terminated specifically in instances, then from there find the name of the VPC. Now that I have found those, I know how many more NAT gateways I need to build. 

Based on a recommendation from a coworker, I add jq which is a very powerful JSON processor that blends awk, sed and grep for JSON objects. It was a bit complex to learn, but now that I have some skills, it will be very handy in the future!

Friday, April 22, 2016

Finding assets in Chef

TL;DR

 knife search node "manufacturer:Dell* OR manufacturer:HP*" -a fqdn -a dmi.system.manufacturer -a dmi.system.product_name -a dmi.system.serial_number 

Background

Today I was asked if the data center inventory was up to date... Well, no, it wasn't... I was looking for ways to find out what was in the data center without having to make the hour round trip.

I thought, "I wonder what's in Ohai". Low and behold, node[:dmi][:system][:manufacturer] is the name of the hardware manufacturer. WooHoo! A little knife search magic, and I get: 
 knife search node "manufacturer:Dell* OR manufacturer:HP*" -a fqdn -a dmi.system.manufacturer -a dmi.system.product_name -a dmi.system.serial_number
host.mydomain.com:
  dmi.system.manufacturer:  Dell Inc.
  dmi.system.product_name:  PowerEdge R720xd
  dmi.system.serial_number: XX0099AA
  fqdn:                     host.mydomain.com

There it is, a one line asset inventory. This is specifically looking for Dell and HP hardware. It is pretty easy to extend this to any other hardware platform, including virtual guests. If you are using RedHat KVM, you can search "manufacturer:Red*".

There are a few formatting options as well, I tend to like JSON output. So, through in a -Fj and you get nice pretty JSON object.