Skip to content

Instantly share code, notes, and snippets.

View zxkane's full-sized avatar

Meng Xin Zhu zxkane

View GitHub Profile
@zxkane
zxkane / mirror-multi-arch-repos.sh
Created July 4, 2024 16:28
Mirror multiple arch images from Docker Hub to AWS Public ECR
#!/bin/bash
set -o errexit # exit on first error
set -o nounset # exit on using unset variables
set -o pipefail # exit on any error in a pipeline
set -x # enable debugging
# Script to mirror multi-arch images from Docker Hub to Amazon ECR Public.
# Usage: ./mirror-multi-arch-repos.sh <source-image>:<tag> <ecr-repo-name>
@zxkane
zxkane / index.mjs
Created April 26, 2024 09:00
simple js app access ddb and states API
import { DynamoDBClient} from '@aws-sdk/client-dynamodb';
import { GetCommand } from '@aws-sdk/lib-dynamodb';
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
import { SFNClient, ListExecutionsCommand } from '@aws-sdk/client-sfn';
const logRequestMiddleware = (next, _context) => async (args) => {
console.log('Request:', args.request);
return next(args);
};
@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 [email protected] --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 [email protected] --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