Skip to content

Instantly share code, notes, and snippets.

View datahaikuninja's full-sized avatar

Jundai Takashina datahaikuninja

View GitHub Profile
## CloudFrontのアクセスログ調査
### 4xx/5xxで応答したリクエストの集計
cat * | awk -F' ' '$2 ~ "xx:[0-9][0-9]:[0-9][0-9]" && $9 ~ "4[0-9][0-9]" {print $5}'| sort | uniq -c | sort -r
### 2xx以外のIP集計
cat * | awk -F' ' '($2 ~ "xx:[0-9][0-9]:[0-9][0-9]") && !($9 ~ "2[0-9][0-9]") {print $5}'| sort | uniq -c | sort -r
### 2xx以外のURI集計
cat * | awk -F' ' '$2 ~ "xx:[0-9][0-9]:[0-9][0-9]" && !($9 ~ "2[0-9][0-9]") {print $8}'| sort | uniq -c | sort -r
# S3のAWS CLIのチートシート
### ファイル数、ファイルサイズ取得
aws s3 ls s3://path/to/file --recursive --human --sum
### Bucket PolicyをJSONで取得
aws s3api get-bucket-policy --bucket {bucket name} --query Policy --output text | jq . --indent 4
### 圧縮されたアクセスログのダウンロード&解凍
aws s3 cp s3://bucketname/path/ . --recursive --exclude "*" --include "*.log.gz"; find . -name '*.gz' | xargs -n1 gunzip
@datahaikuninja
datahaikuninja / aws_cli_rds.sh
Last active October 15, 2023 02:36
My aws cli rds command cheat sheet
# RDSのAWS CLIチートシート
# 利用可能なエンジンバージョンを調べるコマンド
aws rds describe-orderable-db-instance-options \
--engine aurora-postgresql \
--db-instance-class db.r5.large \
--query 'OrderableDBInstanceOptions[].[DBInstanceClass,StorageType,Engine,EngineVersion]' \
--output table \
--region ap-northeast-3
@datahaikuninja
datahaikuninja / aws_cli_ec2.sh
Last active October 15, 2023 02:28
My aws cli ec2 command cheat sheet
# ec2のAWS CLIのチートシート
@datahaikuninja
datahaikuninja / aws_cli_logs.sh
Last active October 15, 2023 02:31
My aws cli logs command cheat sheet
# CloudWatchLogsのAWS CLIチートシート