Skip to content

Instantly share code, notes, and snippets.

View kshailen's full-sized avatar

Shailendra kshailen

View GitHub Profile
#!/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 / Connecting_postgress_RDS_from_local_via_bastion.md
Last active May 14, 2024 11:51
Ways to connect to postgress RDS instance from bastion host and from local host

When it comes to databases and AWS VPC, best practice is to place your database in private subnet. By definition, private subnet in AWS is not reachable from the Internet because no Internet gateway is attached to private subnet. This is the way you protect your data. This kind of configuration is good for security but bad for data management.

How can you easily access and manage your secured data?

basic_RDS_bastion_architecture

There are two basic ways to acees it.

  1. Access postgres RDS from bastion host. There are following requirements for this.
@kshailen
kshailen / test_CreateLogFile.py
Created September 15, 2017 02:51
Testing log file creation in /var/log/msi directory
import requests
import json
import os
import subprocess
import skycommon
class When_getting_machine_list_from_fleet_and_comparing_with_elastic_machine_list:
def __init__(self):
@kshailen
kshailen / CheckUpdateCertificates.sh
Last active August 23, 2017 14:40
CulsterManagerAPI Check
#!/bin/bash
#Check for paas-cluster-manager
HOST=`fleetctl list-units | grep paas-cluster-manager| grep -w active | grep running |head -1 | awk '{print $2}' | awk -F"/" '{print $NF}'`
if [ -z $HOST ]then
echo "paas-cluster-manager is not running in this Cluster"
exit 1
@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