Skip to content

Instantly share code, notes, and snippets.

View kshailen's full-sized avatar

Shailendra kshailen

View GitHub Profile
@kshailen
kshailen / Vagrantfile
Created July 19, 2020 12:02 — forked from crissilvaeng/Vagrantfile
Puppet Lab with Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<-SCRIPT
wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
dpkg -i puppetlabs-release-pc1-xenial.deb
apt-get update
SCRIPT
$server = <<-SCRIPT
@kshailen
kshailen / s3_multipart_upload.py
Created May 9, 2020 05:17 — forked from teasherm/s3_multipart_upload.py
boto3 S3 Multipart Upload
import argparse
import os
import boto3
class S3MultipartUpload(object):
# AWS throws EntityTooSmall error for parts smaller than 5 MB
PART_MINIMUM = int(5e6)
@kshailen
kshailen / README.md
Created April 30, 2020 06:27 — forked from Eyjafjallajokull/README.md
AWS EBS - Find unused snapshots

This script can help you find and remove unused AWS snapshots and volumes.

There is hardcoded list of regions that it searches, adjust the value to suit your needs.

Use snapshot.py snapshot-report to generate report.csv containing information about all snapshots.

snapshot.py snapshot-cleanup lets you interactively delete snapshot if it finds it is referencing unexisting resources.

./snapshots.py --help
#!/bin/bash
# exit when the command fails
set -o errexit;
# exit when try to use undeclared var
set -o nounset;
accessKeyToSearch=${1?"Usage: bash $0 AccessKeyId"}
@kshailen
kshailen / sec_groups_aws.py
Created April 29, 2020 01:13 — forked from toddlers/sec_groups_aws.py
Listing AWS Security groups with Python boto
#!/usr/bin/python
# Script will list all instances, all security groups and their rules for desired profile
# Before using script, you need to create "profile" file, which is ~/.aws/credentials where you put your AWS keys like this:
#
# [dev]
# aws_access_key_id = *****
# aws_secret_access_key = *****
#
# .. and then use it in this script
@kshailen
kshailen / flat_to_mongo.py
Created April 17, 2020 05:35 — forked from gartenfeld/flat_to_mongo.py
Import data from a flat file into MongoDB.
import sys
import re
import codecs # UniCode support
from pymongo import Connection # For DB Connection
from pymongo.errors import ConnectionFailure # For catching exeptions
def main():
# MongoDB connection
try:
@kshailen
kshailen / get_ec2_instances.sh
Created April 17, 2020 01:10 — forked from fboaventura/get_ec2_instances.sh
List all EC2 instances
#!/usr/bin/env bash
# Prereqs:
# Ubuntu 16.04+: apt install awscli jq
# Centos 7+ : yum install awscli jq
set +m
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do
aws ec2 describe-instances --region "$region" | jq ".Reservations[].Instances[] | {type: .InstanceType, state: .State.Name, tags: .Tags, zone: .Placement.AvailabilityZone}" &
done; wait; set -m
@kshailen
kshailen / boto3_listinstances_example.py
Created April 17, 2020 01:07 — forked from mda590/boto3_listinstances_example.py
Example using boto3 to list running EC2 instances
import boto3
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
# create filter for instances in running state
filters = [
{
'Name': 'instance-state-name',
'Values': ['running']
@kshailen
kshailen / 01_get_account_id_for_user_ec2instance_role_or_lambda.py
Created April 8, 2020 07:22 — forked from gene1wood/01_get_account_id_for_user_ec2instance_role_or_lambda.py
Method to determine your AWS account ID using boto3 for either a user or an ec2 instance or lambda function
import boto3
print(boto3.client('sts').get_caller_identity()['Account'])
@kshailen
kshailen / elasticsearch.yml
Created August 4, 2017 09:44 — forked from alinpopa/elasticsearch.yml
elasticsearch.yml example
name: ${HOSTNAME}
# The cluster should be named with the name of the AD domain
cluster:
name: bldrprod-0.14.0
routing:
allocation:
# As small as possible, very large performance hits during recovery
concurrent_recoveries: 1