Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html
amazon_ips=( $(curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="AMAZON") | .ip_prefix') )
ec2_ips=( $(curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="EC2") | .ip_prefix') )
containsElement () {
local element match="$1"
shift
for element
do [[ "$element" == "$match" ]] && return 0; done
const axios = require('axios');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function fetch_retry(url,n){
@serkanh
serkanh / gist:a7b41f4c7625d821d02d477556890ff6
Created February 12, 2018 20:32
s3fs/ecs setup ec2-userdata
#!/bin/bash
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
yum install -y aws-cli
yum install epel-release
sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/epel.repo
yum update -y
yum install -y gcc libstdc++-devel gcc-c++ fuse fuse-devel curl-devel libxml2-devel mailcap automake openssl-devel git
git clone https://github.com/s3fs-fuse/s3fs-fuse
cd s3fs-fuse/
./autogen.sh

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@serkanh
serkanh / combin
Created August 28, 2017 20:24
combine multiple log files to single file.
find . -name "*.log" -print0 | xargs -0 -I file cat file > ~/combined.log
#!/bin/bash
#original https://gist.github.com/weavenet/f40b09847ac17dd99d16
bucket=$1
set -e
echo "Removing all versions from $bucket"
versions=`aws --region=us-west-2 s3api list-object-versions --bucket $bucket |jq '.Versions'`
markers=`aws --region=us-west-2 s3api list-object-versions --bucket $bucket |jq '.DeleteMarkers'`
#If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
#!/bin/bash
set -euox pipefail
echo "Please enter profile to use"
read PROFILE
echo "Please enter region to use"
read REGION
echo "Please enter ELBPORT to use"
read ELBPORT
#encrypt text
aws --profile=jumpstart kms encrypt \
--key-id <YOUR-KEY-ID> \
--plaintext fileb://test \
--query CiphertextBlob \
--output text | base64 --decode > testencrypted.txt
#decrypt text
aws --profile=jumpstart kms decrypt \
--ciphertext-blob fileb://testencrypted.txt \
@serkanh
serkanh / gist:677a0d0bd14f0db8c45ab1de60a6f8e1
Created April 12, 2017 12:45
Generate ssh config file for ECS clusters
#/bin/bash
#set -x
#set -o
CLUSTER_NAME=${1:-"dev1"}
BASTION_NAME=${2:-"ha-bastion"}
PROFILE_NAME=${3:-"HA"}
CONTAINER_INSTANCE=$(aws --profile="${PROFILE_NAME}" ecs list-container-instances --cluster "${CLUSTER_NAME}" --query [containerInstanceArns][0][*] --output text | xargs -n1 -I{} echo {} | cut -d '/' -f 2)