Skip to content

Instantly share code, notes, and snippets.

View alexandrerocco's full-sized avatar
🏠
Working from home

Alexandre Rocco alexandrerocco

🏠
Working from home
View GitHub Profile
@alexandrerocco
alexandrerocco / find_iam_user.py
Last active August 29, 2015 14:05 — forked from OnlyInAmerica/find_iam_user.py
Finds an AWS IAM user that corresponds to the access key passed by the command line parameter.
# Find the IAM username belonging to the command line parameter
# Useful for finding IAM user corresponding to a compromised AWS credential
# Requirements:
#
# Environmental variables:
# AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
# python:
# boto
@alexandrerocco
alexandrerocco / fix-unassigned-shards.sh
Last active December 21, 2015 10:05
Fix unassigned shards in Elasticsearch, you may lose data!
#!/bin/bash
NODE="YOUR NODE NAME"
IFS=$'\n'
for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands": [
{
@alexandrerocco
alexandrerocco / delete-test-queues.sh
Created September 6, 2021 13:44
Deletes test or old AWS SQS queues that matches the prefix
prefix=your-queue-prefix"
region="your-region"
queues=$(aws sqs list-queues --queue-name-prefix $prefix --region $region)
for q in ${queues[@]}
do
if [ "${q:0:1}" == "\"" ]; then
x=${q:1:${#q}-3}
if [ $x != "QueueUrls" ]; then
aws sqs delete-queue --region $region --queue-url $x
fi
@alexandrerocco
alexandrerocco / aws-key-pair-find-delete.sh
Created November 29, 2021 23:27
Lists unused AWS key pair and delete if needed
# List key pairs on the account
aws ec2 describe-key-pairs --query 'KeyPairs[*].KeyName' --output table
# Find instances that uses a key pair you found out above
aws ec2 describe-instances --filters Name=instance-state-name,Values=running Name=key-name,Values="KP-NAME" --query 'Reservations[*].Instances[*].InstanceId'
# If you get an empty response, you can opt to delete it with:
aws ec2 delete-key-pair --key-name KP-NAME