Skip to content

Instantly share code, notes, and snippets.

View zxkane's full-sized avatar

Mengxin Zhu zxkane

View GitHub Profile
@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
@zxkane
zxkane / policy.json
Created March 12, 2020 14:59
readonly permissions for some AWS services
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1584020444106",
"Action": [
"serverlessrepo:GetApplication",
"serverlessrepo:GetApplicationPolicy",
"serverlessrepo:GetCloudFormationTemplate",
"serverlessrepo:ListApplicationDependencies",
@zxkane
zxkane / route53.delete-records.json
Last active February 14, 2020 04:08
Create/Update/Delete DNS records in Route 53 hosted zone in CLI
{
"Comment": "Delete CNAME record in route 53 hosted zone",
"Changes": [
{
"Action": "DELETE",
"ResourceRecordSet": {
"Name": "pypi.mirrors.testtest.vme360.com",
"Type": "CNAME",
"TTL": 300,
"ResourceRecords": [
@zxkane
zxkane / cluster.yml
Last active May 20, 2020 02:56
Create a EKS cluster with IAM for service account
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: cluster-3
region: cn-northwest-1
nodeGroups:
- name: ng2-private
@zxkane
zxkane / .zshrc
Created November 12, 2019 07:17
aws shortcuts
# aws ec2 alias or quick functions
alias ec2-instance-list="aws ec2 describe-instances --output table --query 'Reservations[*].Instances[*].{Instance:InstanceId,Type:InstanceType,AZ:Placement.AvailabilityZone,Name:Tags[?Key==\`Name\`]|[0].Value,Dns:NetworkInterfaces[0].Association.PublicDnsName,State:State.Name}' --filters 'Name=instance-state-code,Values=16'"
alias ec2-terminate-instance="aws ec2 terminate-instances --instance-ids"
function _ec2-launch {
templateName='my-instances-launch-template'
amiid="$1"
if [ -z "$amiid" ]; then
echo 'AMI is missing'
return
@zxkane
zxkane / user-date.sh
Last active October 29, 2019 08:02
Test AWS S3 download performance in Ubuntu LTS 18.04
#!/bin/bash -x
add-apt-repository ppa:plushuang-tw/uget-stable -y
apt install aria2 parallel iotop tmux python3-pip -y
pip3 install awscli --upgrade --user
export AWS_DEFAULT_REGION=ap-northeast-1
SECONDS=0
seq 1 5 | parallel --will-cite -j 5 'url=$(aws s3 presign s3://<your bucket>/test-files/file-{});aria2c --file-allocation=none -c -x 4 -s 4 -d /dev -o null $url'
duration=$SECONDS
RESULT=result-$(curl http://169.254.169.254/latest/meta-data/instance-type)-$(curl http://169.254.169.254/latest/meta-data/instance-id)-seconds-${duration}
touch /tmp/$RESULT
@zxkane
zxkane / route53.sh
Created September 18, 2019 10:12
The private hosted route of Route53 associates with the VPC in another account
export AWS_DEFAULT_PROFILE=account_a(has route53)
aws route53 create-vpc-association-authorization --hosted-zone-id zoneid --vpc VPCRegion=ap-southeast-1,VPCId=vpc-xxxx
export AWS_DEFAULT_PROFILE=account_b(has vpc-xxxx)
aws route53 associate-vpc-with-hosted-zone --hosted-zone-id zoneid --vpc VPCRegion=ap-southeast-1,VPCId=vpc-xxxx