Skip to content

Instantly share code, notes, and snippets.

@hflamboauto1
hflamboauto1 / example.sh
Created July 6, 2016 11:04 — forked from magnetikonline/example.sh
AWS EC2 extract IAM role data from HTTP instance data using bash & curl.
#!/bin/bash
IAM_BASE_URL="http://169.254.169.254/latest/meta-data/iam/security-credentials"
IAMRoleName=$(curl -s $IAM_BASE_URL/)
IAMRoleData=$(curl -s $IAM_BASE_URL/$IAMRoleName/)
IAMRoleAccessKeyID=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"AccessKeyId"[^"]+"([^"]+)",?/\1/p')
IAMRoleAccessKeySecret=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"SecretAccessKey"[^"]+"([^"]+)",?/\1/p')
IAMRoleToken=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"Token"[^"]+"([^"]+)",?/\1/p')
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:03 — forked from magnetikonline/README.md
SSH forward local port to remote AWS RDS MySQL instance.

SSH forward local port to remote AWS RDS instance

The scenario:

  • Connectivity to remote server (e.g. EC2 instance) over SSH.
  • Connectivity to AWS RDS MySQL instance from remote server only (due to security group/firewall settings).
# forward requests from 127.0.0.1:6400 -> RDS.ENDPOINT.rds.amazonaws.com:3306
# add [-f] switch to background ssh process
$ ssh -vvvN \
	-L 6400:RDS.ENDPOINT.rds.amazonaws.com:3306 \
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:03 — forked from magnetikonline/README.md
Transfer MySQL databases between AWS RDS instances.

Transfer MySQL databases between AWS RDS instances

The situation

  • Two AWS RDS MySQL databases - moving databases from source to destination.
  • Both databases are not publicly accessible, only via an EC2 instance(s) - e.g. you have setup your security groups.
  • Can SSH to a target EC2 instance (but of course).

What it does

  • Sets up two SSH port forwards on local machine - one to the source database, another to target.
  • Via calls to transferDatabase():
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:03 — forked from magnetikonline/README.md
AWS CLI S3 usage examples.
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:02 — forked from magnetikonline/README.md
Bash if conditions with functions().

Bash if conditions with functions()

Some examples of calling bash functions in if; then; fi conditionals - both functions that echo and return.

#!/bin/bash

function functionOne {

	echo -n "$1 - $2"
}
@hflamboauto1
hflamboauto1 / mysqlslavecheck.sh
Created July 6, 2016 11:01 — forked from magnetikonline/mysqlslavecheck.sh
Example bash script for a PRTG SSH script sensor - this one for MySQL slave to master checks.
#!/bin/bash
# query MySQL for slave replication status
# note: requires [~/.my.cnf] to be present a populated with valid MySQL password
mysql \
-u root \
-Be "SHOW GLOBAL STATUS LIKE 'Slave_running'" | \
tail -n1 | grep -Pqe "^Slave_running\tON$"
if [ $? -eq 0 ]; then
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:01 — forked from magnetikonline/README.md
Template for bash getopts usage.

Template for bash getopts usage

#!/bin/bash -e

function usage {

	cat <<EOM
Usage: $(basename "$0") [OPTION]...
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 10:59 — forked from magnetikonline/README.md
AWS clone VPC route table and routes.

AWS clone VPC route table and routes

Python script to clone an existing VPC route table. Script output is a series of AWS CLI calls to create the route table and assign routes.

Update AWS_TARGET_REGION and SOURCE_ROUTE_TABLE_ID to suit.

Note: does not currently support NAT Gateways routes due to Boto 2 API limitation.

Example

$ ./clone-route-table.py
@hflamboauto1
hflamboauto1 / haproxy.cfg
Created April 19, 2016 20:28
Here's a sample WORKING haproxy config for websockets / socketio. We were able to get socketio working on an Amazon ELB with just one node, but when we added multiple nodes, we saw weird client issues. So, we decided to use HAProxy on Ubuntu 12.04 and spent significant time trying to get just the right configuration (haproxy.cfg). Note though th…
global
#debug
#daemon
log 127.0.0.1 local0
defaults
log global
option httplog
frontend unsecured *:80