Skip to content

Instantly share code, notes, and snippets.

View zxkane's full-sized avatar

Mengxin Zhu zxkane

View GitHub Profile
@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
@zxkane
zxkane / post-publish.sh
Last active February 8, 2022 10:37
Those scripts are deprecated, see e2e example for detail, https://github.com/aws-samples/cdk-bootstrapless-synthesizer/tree/main/sample-pipeline for detail. use CDK customize synthesizer to publish assets, https://github.com/aws-samples/cdk-bootstrapless-synthesizer.
#!/bin/bash
set -euxo pipefail
publish_s3_assets() {
local name=$1
local prefix=$2
aws s3 ls s3://$name/$prefix --recursive | awk '{print $4}' | xargs -I {} -n 1 aws s3api put-object-acl --acl public-read --bucket $name --key {}
}
@zxkane
zxkane / push-helm-chart-to-all-ecr-regions.sh
Created September 27, 2021 09:42
push helm chart to all ecr regions
#!/bin/bash -xe
create_repo() {
local name=$1
local region=$2
# create ecr repo
aws ecr create-repository --region $region --repository-name "$name" --image-tag-mutability IMMUTABLE --image-scanning-configuration scanOnPush=true --encryption-configuration encryptionType=AES256 2>/dev/null
# set repo permission
@zxkane
zxkane / sagemaker-endpoint-invoke.py
Created August 26, 2021 04:32
invoke sagemaker endpoints without AWS SDK
# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# This file is licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied. See the License for the specific
@zxkane
zxkane / diff.py
Last active October 24, 2022 07:40
diff two dataset by pandas
import pandas as pd
import os
import glob
import logging
pandas_etl_data_dir = '/etl-diff/panda-output'
spark_etl_data_dir = '/etl-diff/spark-output'
def get_logger(name):
logger = logging.getLogger(name)
@zxkane
zxkane / gitops-prod.yml
Last active March 1, 2022 07:18
eksctl-collections
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: gitops-cluster-prod
region: ap-southeast-1
version: '1.21'
karpenter:
version: 0.4.3
createServiceAccount: true
managedNodeGroups: