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 / update-ecs-cluster-capacity-providers.sh
Last active January 20, 2023 13:54
Update the capacity providers of your existing ECS clusters for Fargate
# 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
@pahud
pahud / cdk-fargate-cn.ts
Created October 9, 2019 15:08
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 April 4, 2020 11:55
CDK for Amazon EKS with c5.12xlarge nodegroup
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 September 8, 2021 18:27
AWS CLI sample for Elemental MediaConvert create-job actions
#!/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 August 18, 2019 04:39
list s3 bucket names starting with a prefix
# 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 June 28, 2019 03:19
One Time EC2 SSH public key connect
#!/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 April 5, 2023 07:39
ECS Task export/import
# 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 04:50
APIG custom authorizer for header validation
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 April 21, 2019 22:47
nginx deployment yaml for k8s
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
@pahud
pahud / caddy.yaml
Last active April 20, 2019 20:55
update-custom-k8s-objects
---
apiVersion: v1
kind: Service
metadata:
name: caddy-service
spec:
selector:
app: caddy-pod
ports:
- name: web