Skip to content

Instantly share code, notes, and snippets.

View neilkuan's full-sized avatar
🎯
Focusing

Neil Kuan neilkuan

🎯
Focusing
View GitHub Profile
@neilkuan
neilkuan / manifest-buildspec.yml
Created November 18, 2021 11:05
manifest-buildspec.yml
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH}

CloudFormation

# EC2 UserData output log

/var/log/cloud-init-output.log


## cfn-init
## Logs go to /var/log/cfn-init.log
@neilkuan
neilkuan / aws-cdk-fargate-windows-runtime.ts
Created November 2, 2021 10:00
aws-cdk-fargate-windows-runtime.ts
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import { App, Construct, Stack, StackProps } from '@aws-cdk/core';
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 cluster = new ecs.Cluster(this, 'Cluster', {
vpc,
@neilkuan
neilkuan / app.py
Created October 16, 2021 03:26
cross-stack-cdk-python
#!/usr/bin/env python3
import os
from aws_cdk import core
from py_d.db_stack import DbStack
from py_d.lambda_stack import LambdaStack
env = core.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION'))
app = core.App()
db = DbStack(app, "PyDStack", env=env )
@neilkuan
neilkuan / ec2-constructs.ts
Last active October 14, 2021 05:58
ec2-constructs.ts
import * as ec2 from '@aws-cdk/aws-ec2';
import * as sns from '@aws-cdk/aws-sns';
import * as cdk from '@aws-cdk/core';
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as cw_actions from '@aws-cdk/aws-cloudwatch-actions';
export interface AlarmInstanceProps {
readonly UserData?: ec2.UserData;
readonly vpc?: ec2.IVpc;
readonly topic?: sns.Topic;
@neilkuan
neilkuan / amazonlinux2-init-cdk-dev-env.sh
Created October 4, 2021 08:04
amazonlinux2-init-cdk-dev-env.sh
#!/bin/bash
sudo su - ec2-user
sudo yum update -y
sleep 15
sudo yum install docker git vim -y
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
env VERSION=`python tools/getnodeversion.py` make install DESTDIR=`nvm_version_path v$VERSION` PREFIX=""
nvm install --lts
npm
@neilkuan
neilkuan / aws-sdk-nodejs-InstanceMetadata.md
Created August 23, 2021 15:53
aws-sdk-nodejs-InstanceMetadata.md
import { STS, GetCallerIdentityCommandOutput } from '@aws-sdk/client-sts';
import { fromInstanceMetadata } from '@aws-sdk/credential-provider-imds';

let data: GetCallerIdentityCommandOutput;
( async ()=> {
let sts: STS;

    sts = new STS({
 credentials: fromInstanceMetadata({
@neilkuan
neilkuan / ubuntu-20.04-docker-client-only.sh
Created August 11, 2021 08:39
ubuntu-20.04-docker-client-only.sh
#!/bin/bash
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce-cli
docker version
@neilkuan
neilkuan / highlow.py
Created July 23, 2021 08:34
highlow.py
count = 0
while True:
# Start of game?
if count == 0:
start_time = time.time()
num = random.randint(1, 100)
print "I'm thinking of a number from 1 to 100. Try to guess it! (Enter 0 to exit)"
# Guess a number
#!/bin/bash
sudo amazon-linux-extras install nginx1 -y
sudo systemctl start nginx