Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
ip_from_instance() {
echo $(aws ec2 describe-instances \
--filters \
"{\"Name\":\"tag:Name\", \"Values\":[\"$1\"]}" \
"{\"Name\":\"instance-state-name\", \"Values\":[\"running\"]}" \
--query='Reservations[0].Instances[0].PublicIpAddress' | tr -d '"')
}
fetch_s3_file() {
local bucket=$1
local file_path=$2
local iam_policy=$3
local metadata_path="169.254.169.254/latest/meta-data/iam/security-credentials"
CREDENTIALS=$(curl http://$metadata_path/$iam_policy/)
key_id=$(echo $CREDENTIALS | jq '.AccessKeyId' | sed 's/"//g')
key_secret=$(echo $CREDENTIALS | jq '.SecretAccessKey' | sed 's/"//g')
@leonidlm
leonidlm / concatenate-by-filename.sh
Created July 31, 2014 13:37
Concatenate json files by date (which appears as part of the file name)
#
# grouping files of 2014-04-12-01.json format into one json per mday (2014-04-12)
#
distinct_dates=$(ls -l | awk '{print $9}' | awk -F "-" '{count[$1"-"$2"-"$3]++}END{for(j in count) print j}')
for i in $distinct_dates
do
echo "Grouping for $i month"
cat $i-*.json* > /tmp/$i.json
done
@leonidlm
leonidlm / softlayer_api.sh
Created May 15, 2014 23:41
SoftLayer basic curl API interactions
#
# List all the possible options for creating a VirtualGuest
#
curl https://<user>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions.json | python -mjson.tool
#
# Create a new VirtualGuest
#
curl -X POST --data @/tmp/post https://<user>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/createObject