Skip to content

Instantly share code, notes, and snippets.

@sharmaansh21
sharmaansh21 / lambda_function-ECS-cloudwatch-slack.py
Created June 1, 2017 04:06 — forked from dfetterman/lambda_function-ECS-cloudwatch-slack.py
Lambda function that takes ECS Cloudwatch events and sends a notification to Slack
# Written by Dane Fetterman on 12/1/2016
# https://aws.amazon.com/blogs/compute/monitor-cluster-state-with-amazon-ecs-event-stream/
# Where they use a cloud watch event from ECS to notify a SNS topic. We're
# sending a notification directly to slack instead
import requests
import json
from boto3 import session, client
@sharmaansh21
sharmaansh21 / nginx.conf
Created June 10, 2017 08:14 — forked from cpswan/nginx.conf
Using nginx to proxy to an AWS ELB
daemon off;
worker_processes 1;
events { worker_connections 1024; }
http{
sendfile on;
@sharmaansh21
sharmaansh21 / rds_enhanced_monitoring2mackerel_host_metrics.py
Created June 25, 2017 07:54 — forked from ohsawa0515/rds_enhanced_monitoring2mackerel_host_metrics.py
Send metrics of RDS enhanced monitoring(Cloudwatch Logs) to Mackerel host metrics using AWS Lambda.
from __future__ import print_function
from base64 import b64decode
from urllib2 import Request, urlopen
import time
import json
import zlib
from datetime import datetime, timedelta
import boto3
import os
@sharmaansh21
sharmaansh21 / alb_logs.sql
Created August 16, 2017 10:13 — forked from szinck/alb_logs.sql
Athena Table for ALB Logs
-- This creates an athena table that can parse ALB logs.
-- Advantage of this over others are this works when the log ends with a trailing space
-- plus it also breaks the http request into route and params for easier grouping
CREATE EXTERNAL TABLE IF NOT EXISTS alb_logs (
type string,
timestamp string,
elb string,
client_ip string,
client_port int,
@sharmaansh21
sharmaansh21 / cf_create_or_update.py
Created August 28, 2017 15:43 — forked from svrist/cf_create_or_update.py
Update or create a CloudFormation stack given a name and template + params'
'Update or create a stack given a name and template + params'
from __future__ import division, print_function, unicode_literals
from datetime import datetime
import logging
import json
import sys
import boto3
import botocore
@sharmaansh21
sharmaansh21 / vagrant_centos_multi.rb
Created September 14, 2017 05:01 — forked from ashrithr/vagrant_centos_multi.rb
vagrant multi machine centos
# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [
{
name: "server1.local",
eth1: "192.168.0.101",
mem: 1024,
cpu: 1
},
@sharmaansh21
sharmaansh21 / ha_drbd.md
Created September 16, 2017 06:57 — forked from irvingpop/ha_drbd.md
Cloning a Chef Server 12 installation

Customer Scenario

A customer has a Chef Server 12 (HA - DRBD) in Production. They want to test an in-place upgrade (or maintenance) using their current OPC Production data and config. This gives us a good chance to make corrections if we find that their data is too broken for the migrations to handle, and gives the customer experience in managing the upgrade in Production.

The sequence of events will broadly be these:

  • Install the same version of Chef Server on the target HA Test cluster
  • Restore data from Production instance backup (LVM snapshot or full-stop backup)
  • Test
@sharmaansh21
sharmaansh21 / setup-ldap-client.sh
Created October 9, 2017 07:16 — forked from shichao-an/setup-ldap-client.sh
Setup OpenLDAP client server with SSH access
#!/bin/bash
# vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en cc=120
set -e
# Check Ubuntu release
[ "$(lsb_release -sc)" = "trusty" ] || {
echo 'This script should be run on Ubuntu 14.04.' >&2
exit 1
}
@sharmaansh21
sharmaansh21 / gist:0a44efd348e78fa958c460c8eafb33ef
Created October 14, 2017 08:14 — forked from be-hase/gist:e97aea92abfd7749ca09
elasticsearchのindex削除用のcron script

elasticsearchのindexを定期的にcronを使用して削除するscript。

indexにTTLを設定すればいいじゃないかという指摘もありそうですが、
公式ブログに大量のログを保存するときは、TTL設定しているとオーバーヘッドが大きいと書いてあったので、
cronで消すようにします。
http://www.elasticsearch.org/tutorials/using-elasticsearch-for-logs/

Curatorを使えばこういったことも楽にできそうではあるが、
わざわざそのためにPythonをいじるのもアレなので、簡単にシェルスクリプトで書いてみました。

/*
The code below shows how to encrypt and then decrypt some plaintext into a cyphertext using
KMS's Encrypt/Decrypt functions and secretbox (https://godoc.org/golang.org/x/crypto/nacl/secretbox).
The plaintext message is sealed into a secretbox using a key that is generated by kmsClient.GenerateDataKey().
Note that this procedure reuquires that a master key would *already exist in KMS* and that its arn/alias is specified.
The aws library assumes that the proper credentials can be found in the shared file (~/.aws/credentials)
and opts for the 'default' role.
Once sealed, the cyphertext is then unboxed, again by first getting the key from kms (kmsClient.Decrypt),