Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Pahud Hsieh pahud

🏠
Working from home
Block or report user

Report or block pahud

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pahud
pahud / update-ecs-cluster-capacity-providers.sh
Last active Jan 17, 2020
Update the capacity providers of your existing ECS clusters for Fargate
View update-ecs-cluster-capacity-providers.sh
# 1. update your aws cli
# https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
#
# 2. update your existing cluster with capacity providers support
CLUSTER_NAME=fargate
SERVICE_NAME=myservice
FARGATE_WEIGHT=1
FARGATE_SPOT_WEIGHT=1
FARGATE_BASE=1
FARGATE_SPOT_BASE=0
View cdk-fargate-cn.ts
import cdk = require('@aws-cdk/core');
import { Vpc } from '@aws-cdk/aws-ec2';
import { Cluster, ContainerImage, TaskDefinition, Compatibility } from '@aws-cdk/aws-ecs';
import { ApplicationLoadBalancedFargateService } from '@aws-cdk/aws-ecs-patterns';
import path = require('path')
export class FargateAlbSvcStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
@pahud
pahud / eks-cdk-c512xlarge.ts
Last active Nov 2, 2019
CDK for Amazon EKS with c5.12xlarge nodegroup
View eks-cdk-c512xlarge.ts
import cdk = require('@aws-cdk/core');
import eks = require('@aws-cdk/aws-eks');
import iam = require('@aws-cdk/aws-iam');
import autoscaling = require('@aws-cdk/aws-autoscaling');
import { InstanceType } from '@aws-cdk/aws-ec2';
export class CdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
@pahud
pahud / create-job.sh
Last active Dec 15, 2019
AWS CLI sample for Elemental MediaConvert create-job actions
View create-job.sh
#!/bin/bash
#
# Usage: bash create-job.sh S3_INPUT_VIDEO_FILE_PATH
# e.g. bash create-job.sh s3://your-s3-bucket/your-input-video.mov
input=$1
basename=$(basename $input)
newbasename="${basename%%.*}-H264-AAC.mp4"
output="$(dirname $input)/$newbasename"
@pahud
pahud / list-s3-buckets.sh
Created Aug 18, 2019
list s3 bucket names starting with a prefix
View list-s3-buckets.sh
# list buckets starting with 'codebuild'
buckets=($(aws s3api list-buckets --query 'Buckets[?starts_with(Name, `codepipeline-`) == `true`].Name' --output text))
# delete them
for b in ${buckets[@]}
do
aws s3 rb --force s3://${b}
done
@pahud
pahud / one-time-ec2-ssh-connect.sh
Created Jun 28, 2019
One Time EC2 SSH public key connect
View one-time-ec2-ssh-connect.sh
#!/bin/bash
TMPKEY="my-ssh-tmp-key-${RANDOM}"
EC2USER='ec2-user'
generate_ssh_key_pair(){
ssh-keygen -t rsa -f ~/.ssh/${TMPKEY} -N "" && \
chmod 600 ~/.ssh/${TMPKEY}.pub
}
@pahud
pahud / ecs-task-export-import.sh
Last active May 22, 2019
ECS Task export/import
View ecs-task-export-import.sh
# export the task def
family='TaskDefName'
$ aws ecs describe-task-definition --task-definition $family \
--query "taskDefinition.{family:family, taskRoleArn:taskRoleArn, executionRoleArn:executionRoleArn, networkMode:networkMode, containerDefinitions:containerDefinitions, volumes:volumes, placementConstraints:placementConstraints, requiresCompatibilities:requiresCompatibilities, cpu:cpu, memory:memory, tags:tags, pidMode:pidMode, ipcMode:ipcMode, proxyConfiguration:proxyConfiguration}" | jq 'del(.[] | nulls)' > taskDef.json
# import the task def into newFamily task family
$ aws ecs register-task-definition --cli-input-json file://taskDef.json --family newFamily
# one-liner
aws ecs describe-task-definition --task-definition $family \
@pahud
pahud / apig_customer_authorizer.js
Created May 20, 2019
APIG custom authorizer for header validation
View apig_customer_authorizer.js
exports.handler = (event, context, callback) => {
console.log(event)
var token = event.authorizationToken.toLowerCase();
switch (token) {
case 'dalvik':
callback(null, generatePolicy('user', 'Allow', event.methodArn, token));
break;
// case 'deny':
// callback(null, generatePolicy('user', 'Deny', event.methodArn));
// break;
@pahud
pahud / nginx-deployment.yaml
Last active Apr 21, 2019
nginx deployment yaml for k8s
View nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
@pahud
pahud / caddy.yaml
Last active Apr 20, 2019
update-custom-k8s-objects
View caddy.yaml
---
apiVersion: v1
kind: Service
metadata:
name: caddy-service
spec:
selector:
app: caddy-pod
ports:
- name: web
You can’t perform that action at this time.