Skip to content

Instantly share code, notes, and snippets.

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

Pahud Hsieh pahud

🏠
Working from home
View GitHub Profile
@pahud
pahud / ecs.yaml
Created May 21, 2018 10:41
cloudformation for ECS
AWSTemplateFormatVersion: '2010-09-09'
Description: >
AWS CloudFormation template to create a new VPC
or use an existing VPC for ECS deployment
in Create Cluster Wizard. Requires exactly 1
Instance Types for a Spot Request.
Parameters:
EcsClusterName:
Type: String
Description: >
@pahud
pahud / AWS_WAF_HTTP_KeepAlive.md
Created December 27, 2017 07:40
AWS WAF protection for HTTP established connections
a8667f01ae5b:~ hunhsieh$ telnet debug.pahud.net 80
Trying 54.236.168.77...
Connected to debug.pahud.net.
Escape character is '^]'.
GET / HTTP/1.1
Host: debug.pahud.net

HTTP/1.1 200 OK
Date: Wed, 27 Dec 2017 07:37:01 GMT
@pahud
pahud / waf_update_ip_set.py
Last active October 25, 2023 23:18
WAF update ip set
#!/usr/bin/env python
import boto3
client = boto3.client('waf-regional', region_name='us-east-1')
ipSetId='<YOUR_IP_SET_ID>'
def getChangeToken():
response = client.get_change_token()
@pahud
pahud / ASG_PRICE_OPTIMIZER.js
Created August 17, 2017 07:36
ASG_PRICE_OPTIMIZER
'use strict';
console.log('cold start lambda')
var AWS = require('aws-sdk');
var P = require('bluebird');
process.env.AWS_PROFILE='pahud'
var chain = new AWS.CredentialProviderChain();
var credentials,
@pahud
pahud / lambda_invoke_promisified.js
Last active June 24, 2018 17:55
promisified lambda invocation
'use strict';
console.log('=> lambda start')
var AWS = require('aws-sdk')
AWS.config.update({ region: 'us-west-2' });
const lambda = new AWS.Lambda()
const invokePromisified = (params) => {
return new Promise((resolve, reject)=> {
@pahud
pahud / python-redis.py
Created May 29, 2017 06:59
python sample to test Amazon Elasticache for Redis failover
#!/usr/bin/env python
import redis, time, datetime, sys
endpoint='myred.dpchko.ng.0001.usw2.cache.amazonaws.com'
#endpoint='myred-001.dpchko.0001.usw2.cache.amazonaws.com'
def prepareConn(endpoint):
r = redis.StrictRedis(host=endpoint, port=6379, db=0, socket_timeout=1)
return r
@pahud
pahud / README.md
Last active May 28, 2017 00:46
extra nginx.conf for pahud/openresty docker image
@pahud
pahud / svcupdate.go
Created May 7, 2017 14:34
ECS Service rollback
package main
import (
"flag"
"fmt"
"log"
"strconv"
"strings"
"github.com/aws/aws-sdk-go/aws"
@pahud
pahud / delete_all_awslogs.sh.md
Last active October 18, 2023 09:13
delete all aws log groups

specify the region

export AWS_DEFAULT_REGION=ap-northeast-1
aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | \
awk '{print $2}' | grep -v ^$ | while read x; do  echo "deleting $x" ; aws logs delete-log-group --log-group-name $x; done

only delete loggroup name starting with /aws/lambda

@pahud
pahud / ron_test.js
Created April 11, 2017 16:07
test S3 getObject with optional local save with Lambda
'use strict';
var AWS = require('aws-sdk');
var Promise = require('bluebird')
var s3 = Promise.promisifyAll(new AWS.S3());
// var s3 = new AWS.S3();
var fileInfo = {