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 / cdk-eni-ec2.ts
Created December 23, 2020 12:03
cdk eni attach instance
import { App, CfnOutput, Construct, Stack, StackProps } from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const vpc = ec2.Vpc.fromLookup(this, 'Vpc', { isDefault: true });
const subnetId = vpc.privateSubnets[0].subnetId;
@pahud
pahud / cdk-resource-dependson-parameter-demo.ts
Last active December 29, 2020 01:55
create CDK L2 resource depends on parameter demo
import { App, Construct, Stack, StackProps, CfnParameter, CfnCondition, Fn } from '@aws-cdk/core';
import * as sns from '@aws-cdk/aws-sns';
export interface DemoProps { }
export class Demo extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id)
const stack = Stack.of(this);
@pahud
pahud / devcontainer.json
Last active July 20, 2020 17:37
devcontainer.json for aws/aws-cdk
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.128.0/containers/docker-from-docker
{
// "name": "Docker from Docker",
// "dockerFile": "Dockerfile",
"name": "jsii",
"image": "jsii/superchain",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
],
@pahud
pahud / main.ts
Created May 20, 2020 04:08
create or import existing EKS cluster in AWS CDK
import cdk = require('@aws-cdk/core');
import eks = require('@aws-cdk/aws-eks');
import ec2 = require('@aws-cdk/aws-ec2');
import iam = require('@aws-cdk/aws-iam');
import { Stack } from '@aws-cdk/core';
const DEFAULT_CLUSTER_VERSION = '1.16'
export class EksStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
@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
}