Skip to content

Instantly share code, notes, and snippets.

View zxkane's full-sized avatar

Mengxin Zhu zxkane

View GitHub Profile
@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

@zxkane
zxkane / image-all-tags-layers.sh
Last active July 11, 2024 10:35
get size of layers of docker image. Inspired by this post(https://ops.tips/blog/inspecting-docker-image-without-pull/).
#!/bin/bash
set -o errexit
source ./library
# Entry point of the script.
# If makes sure that the user supplied the right
# amount of arguments (image_name)
# and then performs the main workflow:
# 1. retrieve the image digest
# 2. retrieve the layer info of image
@zxkane
zxkane / upload.sh
Created April 23, 2020 13:35
a memo of uploading certificate to AWS IAM
aws iam upload-server-certificate --server-certificate-name mirrors-test.testtest.vme360.com --certificate-body file://cert.pem --private-key file://privkey.pem --certificate-chain file://chain.pem --path '/cloudfront/openmirror/'
@zxkane
zxkane / cert.sh
Created April 23, 2020 13:28
a memo of requesting cert from let's encrypt in cmd
certbot certonly --expand -d pypi.mirrors-test.testtest.vme360.com -d mirrors-test.testtest.vme360.com --config-dir `pwd` --work-dir `pwd` --logs-dir `pwd` --manual --preferred-challenges dns
@zxkane
zxkane / request.sh
Last active April 23, 2020 13:26
a memo of requesting cert from let's encrypt
certbot certonly --expand -d pypi.mirrors-test.testtest.vme360.com -d mirrors-test.testtest.vme360.com --config-dir `pwd` --work-dir `pwd` --logs-dir `pwd` --manual --preferred-challenges dns