Skip to content

Instantly share code, notes, and snippets.

View patrickpierson's full-sized avatar
:shipit:
Ship it!

Patrick Pierson patrickpierson

:shipit:
Ship it!
View GitHub Profile
P0ZLtbaSS8djksbSQ1HyP4TmCz3MK4SkhNVzBXnNh7ijkDeHMAUtqNsZmfyiizcEws2jch3smwKtrc2EdNMFcQ9k6wFBZ8X8SXeEiqvH4jOJ6w5dqFX3ICzIR9UlMHzPoXLklXCwr3XOfb3h99J5u5D4ZDY5F4tqEFeRmkqo0vemVONl41gct3M8mYq2sIgfmVgEqUXGX2800bGu8tfuMvUaiRuGjzDQsSKZVdeD6nkHjJBIYKKcmm6bxLqXut2uzXLRiUsUYb6extJCqerw4cN84WHv9lllQE7xg574axIj9diQnjOtApwxwboopKgLg31p8Ka82vHcMJAYzZVyzqzvcm3gbFJ0iqdUWmta9R9CMELnudqIDkjhNWc5rx1umGpq1LS7Uq3Fbpawxmdybf6B1r654e2rOJ6vcZ6AsF7NEPhjOakWDsHgpd24qbDU4NZyiXkYtDVBoVk3WlA50t7kWKxCOUsMEqGkdgRceCrKL3p0BOovVW2USNeM1Qn92Xoa7RxncqLiB3a9DoxOA8WVEmJ4115scpRqcyocygTJfbZ034yDGzdHthFOM1LPIDSoLmCHNCZ5wAjhfq7fkwbr73tkti1xmF4HG3eVfV8dzXohIdacSnRYWYz8lB68IhTtsUwol68VqtjRIfjHXNQmC688TBlLYHADaulvCpGu9dDUkHh5wc4PM4k8Wi3k9vK8AVmt4kkOigfx0Hw97FwFJqpwE50SoZi1KxBMkOa4jK34ONdlQOGyLN1dSuKMNDiIwnMyAV5ydF8HK2WwlIAmBG5B1DKMhWIOO5iUGziITQJVH5ASNofwA8A8jDRxA20rOmZSspM2C2jwRealmZQsMCCuTSzDunqckJB8eLVK0XRGbOKHdLnMQ4yUExbhj2trVuLpuOnJSuRVKY9uvdQNCnR7NI6KZQqorq6ecEX4EOtVZWaPS9RUmcWNoe8mTpat8m9y2zKHKTtJFNXl5GdITPxvMK0G9Lqft0KubFs8XER6alxGIrjYPhJBIaZK
#!/bin/bash
if [ -z "$1" ]; then
echo "-----------------------------"
aws s3 ls | awk '{print $3}'
echo "-----------------------------"
echo "Please enter a bucket name -- s3du bucket-name"
else
s3du=$(aws s3 ls s3://$1 --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}')
printf "Bucket $1 is "
echo $s3du
# cqlsh to vpc internal ip
cqlsh $(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
# remove exited containers
docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm
# remove images marked with <none>
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

Keybase proof

I hereby claim:

  • I am patrickpierson on github.
  • I am patrickpierson (https://keybase.io/patrickpierson) on keybase.
  • I have a public key ASB_i0tkFyaW6zEwSAroSeWcSBDmAcNkfr9ApIZabUkmtAo

To claim this, I am signing this object:

#!/bin/bash
SERVICE=service
CLUSTER=ecs-cluster
for i in $(aws ecs list-tasks --cluster $CLUSTER --service-name $(aws ecs list-services --cluster $CLUSTER | jq -r '.serviceArns[]' | grep $SERVICE) | jq -r '.taskArns[]'); do aws ec2 describe-instances --instance-ids $(aws ecs describe-container-instances --cluster $CLUSTER --container-instances $(aws ecs describe-tasks --cluster $CLUSTER --tasks $i | jq -r '.tasks[].containerInstanceArn') | jq -r '.containerInstances[].ec2InstanceId') | jq -r '.Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddress'; done;
@patrickpierson
patrickpierson / default aws profile script
Created November 8, 2016 15:43
setup .bashrc to allow you to easily change the default aws profile
# Add this to .bashrc
function default-aws() {
export AWS_PROFILE=$1
}
# close terminal and reopen. Run the command default-aws <profile> and it will change the default profile used.
# This can replace the need to run --profile at the end of a aws cli command. Useful when using something like
# https://github.com/DualSpark/cloudformation-environmentbase which doesnt handle multiple profiles very well
@patrickpierson
patrickpierson / sqs-migrator.py
Last active May 29, 2018 04:25
Migrate messages from one queue to another.
import boto3
from pprint import pprint
source_queue = 'https://sqs.us-east-1.amazonaws.com/AWSACCOUNTID/source-queue'
dest_queue = 'https://sqs.us-east-1.amazonaws.com/AWSACCOUNTID/dest-queue'
import boto3
client = boto3.client('sqs')
import glob2
import json
all_files = glob2.glob('data/**/*.json')
flight_reports = []
altitude_reports = []
speed_reports = []
messages = 0
import geopy.distance
import glob2
import json
from pprint import pprint
all_files = glob2.glob('data/**/*.json')
my_loc = (39.0, -77.0)
_5_miles = 0
import boto3
sqs_client = boto3.client('sqs')
while True:
with open('messages.txt', 'a') as save_file:
messages = sqs_client.receive_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/1234567890123/example',
MaxNumberOfMessages=10