Skip to content

Instantly share code, notes, and snippets.

@aarondodd
aarondodd / query_ec2_older_than
Created February 28, 2018 16:40
Query AWS EC2 instances based on launch time
#!/bin/bash
# Example how to query AWS for nodes that have been online older than a certain date
# Example below returns just the "Name" tag value (intent is for looping through for other actions)
# Example below also filters by "state=running" to excluded stopped or pending instances
# To get newer than a certain date, just alter ?LaunchTime<=${ec2_older_than_date} for the <= to be >=
query_older_than_minutes=10
@aarondodd
aarondodd / aws_query_group
Created February 28, 2018 18:43
get public DNS of EC2 instances tagged with a certain value
aws ec2 describe-instances --region us-east-1 --filters "Name=tag:Group,Values=fancyapp1" --output json --query 'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`].Value,PublicIP:PublicIpAddress}'
@aarondodd
aarondodd / aws_query_group.php
Created February 28, 2018 19:01
Using the AWS PHP SDK to find running nodes by tag value
<?php
require 'aws.phar';
//===================================================================
// Readme:
//===================================================================
// To populate hostnames based on current live values, look up from AWS directly.
// Requires:
// - aws.phar in same folder as this script, or full path specified in the above require
// - IAM role assigned to node that allows Get* for ec2
//
@aarondodd
aarondodd / aurora_instance_resize
Created March 13, 2018 14:56
scale an aurora cluster writer node
#!/bin/bash
instance_size=$1
cluster_id="mycoolcluster-xxxx"
primary_node="mycoolcluster-node"
region="us-east-1"
pending_status=""
check_for='"PendingModifiedValues": {},'
aws rds modify-db-instance --db-instance-identifier "${primary_node}" --db-instance-class "${instance_size}" --apply-immediately --region "${region}"
@aarondodd
aarondodd / update_asg
Created February 28, 2018 15:53
lambda function to replace AMI in launch config and apply to autoscaling group, keeping root volume information
from __future__ import print_function
import json
import datetime
import time
import boto3
print('Loading function')