Skip to content

Instantly share code, notes, and snippets.

View gregtaylor99's full-sized avatar

Greg Taylor gregtaylor99

  • 04:39 (UTC -04:00)
View GitHub Profile
@gregtaylor99
gregtaylor99 / TaggingScripts
Last active December 17, 2015 08:09
RightscaleTagging
Set a Tag on an Instance
#!/bin/sh -ex
instance_id=556677
tag="mytags%3Abar%3Dfoo"
# Issue curl command to get and store the cookie
curl -H "$api_version" -b "$api_cookie" --request PUT https://my.rightscale.com/api/acct/"$api_account"/tags/set?resource_href=/ec2_instances/"$instance_id" -d 'tags[]='"$tag"
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
source 'https://rubygems.org'
group :test do
gem 'chefspec', '~> 1.3'
gem 'foodcritic', '~> 2.1'
gem 'strainer', '~> 3.0'
gem 'test-kitchen', '~> 1.0.0.alpha'
gem 'kitchen-lxc', '~> 0.0.1.beta1'
gem 'knife-spork', '~> 1.0.17'
gem 'hipchat', '~> 0.10.0'
#!/bin/bash
# Replace the following variables for your environment
# zxtm - hostname of your Stingray Traffic Manager
# zxtmuser - username used to log in to Stingray SSH interface
# git_path - path to the git repo you want to store the config backups in
#
# I recommend that zxtmuser is able to log in to the Traffic Manager
# without using a password, using SSH keys.
#
@gregtaylor99
gregtaylor99 / list_latest_ecs_ami.sh
Created March 23, 2018 01:00 — forked from pahud/list_latest_ecs_ami.sh
get latest 3 amazon-ecs-optimized amzn-ami with AWS-CLI and JMESPath Query
$ aws --region ap-northeast-1 ec2 describe-images --owner amazon --query 'Images[?Name!=`null`]|[?contains(Name, `ecs-optimized`) == `true`]|[?contains(Name, to_string(`2016`)) == `true`]|[0:3].[Name,ImageId,CreationDate,Description]' --output text | sort -rk1
amzn-ami-2016.03.g-amazon-ecs-optimized ami-058a4964 2016-08-11T22:26:29.000Z Amazon Linux AMI 2016.03.g x86_64 ECS HVM GP2
amzn-ami-2016.03.e-amazon-ecs-optimized ami-2b08f44a 2016-07-11T22:28:39.000Z Amazon Linux AMI 2016.03.e x86_64 ECS HVM GP2
amzn-ami-2016.03.c-amazon-ecs-optimized ami-095dbf68 2016-05-26T23:32:34.000Z Amazon Linux AMI 2016.03.c x86_64 ECS HVM GP2
# or check the page http://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html for latest AMI ID
@gregtaylor99
gregtaylor99 / list_aws_az.sh
Created March 23, 2018 01:01 — forked from pahud/list_aws_az.sh
list all AWS AZs with aws-cli
$ aws ec2 describe-regions --query 'Regions[*].RegionName' --output table | awk '$2 ~/-/{print $2}' | while read region; do aws ec2 describe-availability-zones --region $region --query AvailabilityZones[*].ZoneName --output table; done | awk '$2 ~/-/{print $2}'
ap-south-1a
ap-south-1b
eu-west-1a
eu-west-1b
eu-west-1c
ap-southeast-1a
ap-southeast-1b
ap-southeast-2a
ap-southeast-2b
@gregtaylor99
gregtaylor99 / ec2_self_tagging.sh
Created March 23, 2018 01:02 — forked from pahud/ec2_self_tagging.sh
EC2 tag itself on instance launch with UserData
#!/bin/bash
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
region=${az%%?}
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
aws ec2 create-tags --resources $instance_id --region $region --tags \
Key=foo,Value=bar \
Key=Name,Value=myname
@gregtaylor99
gregtaylor99 / list_elb_from_instanceId.sh
Created March 23, 2018 01:02 — forked from pahud/list_elb_from_instanceId.sh
list all registered ELB name from a given EC2 instanceId
#!/bin/bash
instanceId='i-XXXXXXXXXXXXX'
aws elb describe-load-balancers --query \
"LoadBalancerDescriptions[?Instances[?InstanceId=='${instanceId}']].LoadBalancerName"
@gregtaylor99
gregtaylor99 / spot_terminating_notify.sh
Created March 23, 2018 01:03 — forked from pahud/spot_terminating_notify.sh
EC2 spot instance terminating notify
#!/bin/bash
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
region=${az%%?}
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
logfile='/tmp/termination-time.out'
sns_arn=${ARN-undefined_arn}
sns_subject=${SUBJECT-"spot instance is terminating"}
@gregtaylor99
gregtaylor99 / deregister_ec2_from_all_elb.sh
Created March 23, 2018 01:05 — forked from pahud/deregister_ec2_from_all_elb.sh
deregister EC2 instanceId from all ELBs
#!/bin/bash
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
region=${az%%?}
list_elb(){
aws --region $region elb describe-load-balancers --query \
"LoadBalancerDescriptions[?Instances[?InstanceId=='${1}']].LoadBalancerName"
}