Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Pahud Hsieh pahud

🏠
Working from home
View GitHub Profile
@pahud
pahud / bootstrap.sh
Last active Aug 30, 2021
AWS SSO + Codespaces
View bootstrap.sh
#!/bin/bash
# video demo - https://www.youtube.com/watch?v=Y8TyE_DNds8
mkdir ~/.tmp && cd $_
# install aws-cli v2
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
sudo ./aws/install
@pahud
pahud / remote_docker_host_m1.md
Last active Jul 3, 2021
Remote Docker Host for M1 laptop
View remote_docker_host_m1.md
  1. Open a new Amazon Linux 2 EC2(amd64) on AWS. Make it spot instance if you prefer.

ssh ec2-user@<EC2_IP> into the EC2 instance:

# install and start docker
$ sudo yum install -y docker
$ sudo service docker start
@pahud
pahud / apprunner.cfn.yaml
Last active Jun 12, 2021
apprunner cfn service
View apprunner.cfn.yaml
Resources:
FlaskService3B7F72B9:
Type: AWS::AppRunner::Service
Properties:
SourceConfiguration:
CodeRepository:
CodeConfiguration:
ConfigurationSource: REPOSITORY
RepositoryUrl: https://github.com/aws-containers/hello-app-runner
SourceCodeVersion:
@pahud
pahud / cdk-eni-ec2.ts
Created Dec 23, 2020
cdk eni attach instance
View cdk-eni-ec2.ts
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 Dec 29, 2020
create CDK L2 resource depends on parameter demo
View cdk-resource-dependson-parameter-demo.ts
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 Jul 20, 2020
devcontainer.json for aws/aws-cdk
View devcontainer.json
// 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
create or import existing EKS cluster in AWS CDK
View main.ts
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 Jul 23, 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 Apr 4, 2020
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);