Skip to content

Instantly share code, notes, and snippets.

View doi-t's full-sized avatar
🧗‍♂️
Be open-minded

Toshiya Doi doi-t

🧗‍♂️
Be open-minded
View GitHub Profile
@doi-t
doi-t / generate_cloudwatch_metric_url.sh
Created September 11, 2018 07:33
View a stacked graph of an EC2 Per-Instance metric for EC2 instances that has prefix you specified.
# As of 2018/09/11
# METEIC can be either NetworkPacketsOut, NetworkPacketsIn, DiskReadOps, StatusCheckFailed, StatusCheckFailed_Instance, NetworkOut, NetworkIn, DiskWriteBytes, StatusCheckFailed_System, CPUUtilization, DiskWriteOps or DiskReadBytes
METRIC='NetworkIn'; REGION='ap-northeast-1'; NAME_TAG_VALUE='your_instance_name_prefix*'; echo "https://${REGION}.console.aws.amazon.com/cloudwatch/home?region=${REGION}#metricsV2:graph=~(view~'timeSeries~stacked~false~metrics~(`aws ec2 describe-instances --filter Name=tag:Name,Values="${NAME_TAG_VALUE}" | jq '.[][].Instances[].InstanceId' --raw-output | sed "s/^/~(~'AWS*2fEC2~'${METRIC}~'InstanceId~'/g" | sed "s/$/~(stat~'Sum))/g" | tr -d '\n'`)~view~'timeSeries~stacked~true~region~'${REGION})"
@doi-t
doi-t / listup_ami_ids.sh
Last active April 14, 2022 11:41
List up all Amazon Linux AMI (HVM / 64-bit) IDs
aws ec2 describe-images --owners self amazon --filters \
Name=virtualization-type,Values=hvm \
Name=architecture,Values=x86_64 \
Name=block-device-mapping.volume-type,Values=gp2 \
| jq -r '.Images | sort_by(.Name)| .[] | select(.Platform != "windows") | .Name + ": " + .ImageId' \
| egrep 'amzn-ami-hvm|ecs-optimized|amzn2-ami-hvm|amzn2-ami-ecs'
@doi-t
doi-t / protocol_buffers_and_grpc_tutorial.md
Last active July 27, 2023 11:12
Protocol Buffers & gRPC Tutorial: Python & Go
@doi-t
doi-t / aws_route53_upsert_a_record.sh
Last active June 6, 2019 21:59
Change an A record of a domain managed by AWS Route53.
#!/bin/bash
set -ex
[ $# -ne 3 ] && echo "Usage $0 <your zone id> <your domain> <your ip>" && exit 1
MY_ZONE_ID=$1
MY_DOMAIN=$2
MY_IP=$3
TMPFILE=$(mktemp /tmp/${MY_DOMAIN}_upsert_${MY_IP}.XXXXXX)
#!/bin/bash
[ $# -ne 1 ] && echo "Usage: $0 <security group id>" && exit 1
SG_ID=$1
MY_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
aws ec2 authorize-security-group-ingress --group-id ${SG_ID} \
--ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges="[{CidrIp=${MY_IP}/32,Description='Open 22 port with awscli'}]"
@doi-t
doi-t / give_me_linux_env_with_current_dir_now.sh
Last active July 13, 2019 06:07
Give me a linux environment with the current working directory right now!
#!/bin/bash
set -ex
IMAGE=${1:-ubuntu}
if [ ${IMAGE} = 'golang' ]; then
TARGET=/go
else
TARGET=/app
fi
@doi-t
doi-t / my_vs_code_settings.md
Last active January 10, 2021 04:08
wip: My VS Code Settings

Update settings.json

{
  "editor.formatOnSave": true,
  "editor.wordWrap": "on",
  "editor.insertSpaces": true,
  "editor.detectIndentation": false,
@doi-t
doi-t / login_to_opsworks_instance_with_session_manager.sh
Last active March 17, 2020 09:18
Login to an opsworks instance from local with AWS session manager
# Install the plugin first
# https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
TARGET_HOSTNAME="<your target hostname>"; \
OPSWORKS_STACK_ID="<your target OpsWorks Stack ID>"; \
REGION="us-east-1"; \
EC2_INSTANCE_ID=$(aws opsworks describe-instances --stack-id ${OPSWORKS_STACK_ID} --region ${REGION} \
| jq --arg TARGET_HOSTNAME "$TARGET_HOSTNAME" \
'.[][] | select(.Hostname | contains($TARGET_HOSTNAME)) | .Ec2InstanceId' --raw-output); \
echo "Connecting to ${EC2_INSTANCE_ID}"; \
aws ssm start-session --target ${EC2_INSTANCE_ID}
SCHEMA_FILE=path/to/schema/file.sql \
REPO=$(git rev-parse --show-toplevel); \
GIT_HASH=$(git rev-parse HEAD); \
schemalex "local-git://${REPO}?file=${SCHEMA_FILE}&commitish=${GIT_HASH}" ${REPO}/${SCHEMA_FILE}
@doi-t
doi-t / manage_milestones_with_gh.md
Last active December 29, 2024 16:23
Manage milestones with gh

Use gh v0.11.0 or later for the "shell" aliases.

Run the following gh alias set commands for each operation. You can confirm the created aliases with gh alias list.

gh listMilestones

gh alias set listMilestones "api graphql -F owner=':owner' -F name=':repo' -f query='
    query ListMilestones(\$name: String\!, \$owner: String\!) {
        repository(owner: \$owner, name: \$name) {
            milestones(first: 100) {