Skip to content

Instantly share code, notes, and snippets.

View zxkane's full-sized avatar

Mengxin Zhu zxkane

View GitHub Profile
@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:
@zxkane
zxkane / push-repo-to-all-ecr-regions.sh
Last active April 26, 2021 09:55
Push a container image to all ECR regions(create the repo if necessary)
#!/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
# Amazon Neptune version 4 signing example (version v2)
# The following script requires python 3.6+
# (sudo yum install python36 python36-virtualenv python36-pip)
# => the reason is that we're using urllib.parse() to manually encode URL
# parameters: the problem here is that SIGV4 encoding requires whitespaces
# to be encoded as %20 rather than not or using '+', as done by previous/
# default versions of the library.
@zxkane
zxkane / snippet.ts
Created March 5, 2021 15:24
how set cfn condition to CDK resources
const standardPartitionCondition = new CfnCondition(this, 'IsStandardPartition', {
expression: Fn.conditionEquals(Aws.PARTITION, 'aws'),
});
const dbUser = 'dashboard';
const docDBCluster = new DatabaseCluster(this, 'DashboardDatabase', {
masterUser: {
username: dbUser,
},
storageEncrypted: true,
@zxkane
zxkane / .gitigore
Last active January 13, 2022 14:46
purge obsolete resources after deleting nexus3 stack created by solution https://github.com/aws-samples/nexus-oss-on-aws
local-empty-dir/
@zxkane
zxkane / import-ssh-keys-in-all-regions.sh
Created October 16, 2020 07:53
import a local ssh key to all AWS regions
#!/bin/bash -x
import_key() {
local name=$1
local path=$2
local region=$3
EXISTINGKEY=`aws ec2 describe-key-pairs --region $region --key-names $name --query 'KeyPairs[].KeyName' 2>/dev/null|jq '.[]'|jq '.'`
if [[ -z $EXISTINGKEY ]]
then
aws ec2 import-key-pair --key-name $name --public-key-material fileb://$path --region $region >/dev/null
@zxkane
zxkane / disable-rules.sh
Created September 20, 2020 16:27
disable rules of aws event bridge
aws events list-rules --name-prefix OpenTunaStack-MonitorStac-Monitor --query 'Rules[].Name' --output json |jq '.[]' |jq '.'|xargs -n 1 aws events disable-rule --name
@zxkane
zxkane / query.sh
Created September 8, 2020 06:00
query latest amazon linux2 AMI
aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn2-ami-hvm-*-ebs" "Name=root-device-type,Values=ebs" "Name=architecture,Values=x86_64" --query 'reverse(sort_by(Images, &CreationDate))[:1]'
@zxkane
zxkane / delete-loggroups.sh
Created July 2, 2020 09:51
delete multiple CloudWatch Log groups via one command
aws logs describe-log-groups --query "logGroups[].logGroupName" --log-group-name-prefix /aws/lambda/func-prefix | jq '.[]' | xargs -n 1 -I{} aws logs delete-log-group --log-group-name {}
@zxkane
zxkane / README.md
Last active January 23, 2022 20:23
Export all images with tags in gcr.io/google-containers

Dump images with tags from repository gcr.io/gcr-containers

Prerequisites

  • Install gcloud
  • Configure account auth via gcloud auth login
  • Install jq

Usage