Skip to content

Instantly share code, notes, and snippets.

View zxkane's full-sized avatar

Meng Xin Zhu zxkane

View GitHub Profile
@zxkane
zxkane / launch.json
Created April 8, 2024 14:59
run/debug a jest test file in vs code
{
"configurations": [
{
"name": "Jest file",
"type": "pwa-node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--runInBand",
@zxkane
zxkane / 1.sh
Created March 19, 2024 07:27
create legacy ClickstreamExploreUser in QuickSight
aws quicksight register-user --region us-east-1 --aws-account-id 1234567890 \
--identity-type IAM --email xx@example.com --user-role ADMIN --namespace default \
--session-name ClickstreamExploreUser \
--iam-arn arn:aws:iam::1234567890:role/clickstream-v12-dev-ClickStreamApiQuickSightEmbedRo-yQ90NyWORHnq
@zxkane
zxkane / 1.sh
Created December 13, 2023 02:21
request a SSL certificate from Let's Encrpt then upload to AWS IAM for CloudFront usage
# install tools
pip3 install certbot acme certbot-dns-route53
#
export DOMAIN_NAME=clickstream.example.com
export CERT_NAME=$DOMAIN_NAME-$(/bin/date +%s)
# request fress SSL cert via DNS chanllege
certbot certonly --dns-route53 -d $DOMAIN_NAME --email your-mail@example.com --agree-tos --non-interactive --work-dir ./ --logs-dir ./ --config-dir ./ -v
@zxkane
zxkane / aws-sdk-v3-custom-logger.ts
Created September 7, 2023 10:21
use custom logger for AWS JS SDK v3
import { DescribeParametersCommand, SSMClient } from "@aws-sdk/client-ssm";
import { UserAgent } from '@aws-sdk/types';
import * as log4js from "log4js";
log4js.configure({
appenders: { out: { type: "stdout" } },
categories: { default: { appenders: ["out"], level: "debug" } },
});
const logger = log4js.getLogger();
@zxkane
zxkane / script.sh
Created June 15, 2023 08:38
dump depenedencies and licenses
npx license-report --fields=name --fields=licenseType --only=prod --output=csv --delimiter=" under the " --package=/path/to/package.json
@zxkane
zxkane / 1.sh
Created February 9, 2023 04:32
create cfn stack for pipeline
aws cloudformation create-stack --template-url https://bucketname.s3.cn-north-1.amazonaws.com.cn/tmp/pipeline.yml --parameters ParameterKey=PipelineType,ParameterValue=Feature ParameterKey=ContainerImageSupport,ParameterValue=true ParameterKey=IsRepositoryExist,ParameterValue=true ParameterKey=RepositoryName,ParameterValue=clickstream-branch-main ParameterKey=RepositoryDescription,ParameterValue=xxx ParameterKey=BranchName,ParameterValue=ingestion-server-del-ecs --capabilities CAPABILITY_IAM --stack-name v5-test
@zxkane
zxkane / create-static-website.ts
Last active September 2, 2022 10:34
todo-restful-api
const cloudFrontS3 = new CloudFrontToS3(this, 'control-plane', {
insertHttpSecurityHeaders: false,
cloudFrontDistributionProps: {
comment: 'It is managed by ServerlessTODO app.',
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2019,
httpVersion: HttpVersion.HTTP2_AND_3,
additionalBehaviors: {
['/prod/*']: {
origin: new HttpOrigin(Fn.select(2, Fn.split('/', api.url)), {
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
@zxkane
zxkane / run.sh
Last active December 12, 2022 07:25
mirror helm charts to s3
#!/bin/bash
set -euxo pipefail
BUCKET=aws-gcr-solutions-assets
mirror-helm() {
local repoName=$1
local chartName=$2
aws logs put-resource-policy --policy-name AWSLogDeliveryWrite20150319 \
--policy-document '
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSLogDeliveryWrite",
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
@zxkane
zxkane / setup.sh
Last active June 13, 2022 15:07
use kind to debug gitops flux locally
# set kubeconfig for your kind cluster
export KUBECONFIG=$HOME/.kube/kind
# create kind cluster
kind create cluster --name gitops
# provisioning flux
flux install --components-extra=image-reflector-controller,image-automation-controller --export > gotk-components.yaml
cat <<EOF > kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1