Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
jq を駆使して aws cli の運用を最適化
Search
Sho
October 29, 2024
Programming
190
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
jq を駆使して aws cli の運用を最適化
#midosuji_tech
Sho
October 29, 2024
More Decks by Sho
See All by Sho
Java ランタイムからカスタムランタイムに行き着くまで
ririru0325
1
530
チームでリファクタリングを進めるために
ririru0325
0
130
AWS歴6年のSaaS企業が直面する低凝集マイクロサービスの課題とその解決アプローチ
ririru0325
0
38
エムオーテックスの現場_-_SaaSプロダクトのアーキテクチャ変革と技術負債解消の道のり
ririru0325
0
75
できたこと・やっていきたいこと
ririru0325
0
62
サーバーレス SaaS における運用監視の負荷軽減のためのアプローチ
ririru0325
0
430
サーバーレスアプリケーションの観測を適正化し、運用負荷を減らしていってる話
ririru0325
0
77
Lambdaのこと
ririru0325
0
110
Other Decks in Programming
See All in Programming
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.6k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.4k
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
180
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
210
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.5k
Webフレームワークの ベンチマークについて
yusukebe
0
190
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
620
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
1k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
160
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
130
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.7k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
930
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
1
3.8M
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
400
Tell your own story through comics
letsgokoyo
1
980
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
Automating Front-end Workflow
addyosmani
1370
210k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
170
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
430
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Transcript
jq を駆使して aws cli の運用を 最適化
自己紹介 • 名前:桑名 翔 • 所属:エムオーテックス株式会社 • 年齢:28 • 資格:
X(旧Twitter)
今日の話 • jqの概要 • aws cliの概要 • jqの使い方 • 一緒に使いたいコマンド紹介
• 明日みんなに使ってほしいサンプル
jqとは • jq is a lightweight and flexible command-line JSON
processor. ◦ 翻訳: jqは軽量で柔軟なコマンドラインJSONプロセッサーです。 ◦ 引用: https://jqlang.github.io/jq/ • A jq program is a "filter": it takes an input, and produces an output. ◦ 翻訳: jqプログラムは「フィルター」であり、入力を受け取り、出力を生成する。 ◦ 引用: https://jqlang.github.io/jq/manual/
aws cliとは • AWS コマンドラインインターフェイス (AWS CLI) は、AWS のサービ スを管理するための統合ツールです。
◦ 引用: https://aws.amazon.com/jp/cli/ • aws s3 ls • aws dynamodb list-tables • など
jqの使い方 { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } aws dynamodb scan --table-name orders_table ¥ > items.json aws cliによるリソースの操作や情報の取得は 料金が発生することが多いので、実行結果は 保存することをお勧めします
jqの使い方 { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } 特定の要素を抽出 cat items.json | jq '.Items[].order_id.S' "1001" "1002" "1003" 実行結果
jqの使い方 { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } 条件に基づくフィルタリング cat items.json | jq '.Items[] | select(.status.S == "shipped")' { "order_id": { "S": "1001" }, "customer": { "M": { "name": { "S": "Alice" } } }, "status": { "S": "shipped" } } 実行結果
jqの使い方 { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } csvの作成 cat items.json | jq -r '.Items[] | [.order_id.S, .customer.M.name.S, .status.S] | @csv' "1001","Alice","shipped" "1002","Bob","processing" "1003","Charlie","delivered" 実行結果
一緒に使いたいコマンド紹介
sed { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } JSONデータから抽出した文字列の一部を置換する cat items.json | jq -r '.Items[].customer.M.name.S' | sed 's/Alice/Alicia/' Alicia Bob Charlie 実行結果
awk { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } JSONデータから抽出した名前の長さを計算する cat items.json | jq -r '.Items[].customer.M.name.S' | awk '{ print $0, length($0) }' Alice 5 Bob 3 Charlie 7 実行結果
sort { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } JSONデータから抽出した名前をアルファベット順にソートする cat items.json | jq -r '.Items[].customer.M.name.S' | sort Alice Bob Charlie 実行結果
uniq { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } JSONデータから抽出した名前の重複を取り除く cat items.json | jq -r '.Items[].customer.M.name.S' | sort | uniq Alice Bob Charlie 実行結果
wc { "Items": [ { "order_id": {"S": "1001"}, "customer": {"M":
{"name": {"S": "Alice"}}}, "status": {"S": "shipped"} }, { "order_id": {"S": "1002"}, "customer": {"M": {"name": {"S": "Bob"}}}, "status": {"S": "processing"} }, { "order_id": {"S": "1003"}, "customer": {"M": {"name": {"S": "Charlie"}}}, "status": {"S": "delivered"} } ] } JSONデータから抽出した顧客の名前の数をカウントする cat items.json | jq -r '.Items[].customer.M.name.S' | sort | uniq | wc -l 3 実行結果
明日みんなに使ってほしいサンプル
• ターゲット ◦ Lambdaをデプロイしたことがあるアナタ ◦ 新しいロググループを作ったアナタ 明日みんなに使ってほしいサンプル
• ターゲット ◦ Lambdaをデプロイしたことがあるアナタ ◦ 新しいロググループを作ったアナタ 明日みんなに使ってほしいサンプル ログの保持期間、設定しましたか?
明日みんなに使ってほしいサンプル えっ、してない??
明日みんなに使ってほしいサンプル 大丈夫、いい抽出方法がありますよ
• CloudWatch Logs の 保持期間が設定されていないグループの一覧を抽出する • まずは aws cli コマンド
◦ aws logs describe-log-groups 明日みんなに使ってほしいサンプル { "logGroups": [ { "logGroupName": "/aws/lambda/us-east-1.test2", "creationTime": 1598840774656, "metricFilterCount": 0, "arn": "arn:aws:logs:ap-northeast-1:xxxxxxxxxxxx:log-group:/EC2/Session/:*", "storedBytes": 58315421, "logGroupClass": "STANDARD", "logGroupArn": "arn:aws:logs:ap-northeast-1:xxxxxxxxxxxx:log-group:/EC2/Session/" }, ︙ { "logGroupName": "/aws-glue/crawlers", "creationTime": 1567491367253, "metricFilterCount": 0, "arn": "arn:aws:logs:ap-northeast-1:xxxxxxxxxxxx:log-group:/aws-glue/crawlers:*", "storedBytes": 10970538, "logGroupClass": "STANDARD", "logGroupArn": "arn:aws:logs:ap-northeast-1:xxxxxxxxxxxx:log-group:/aws- glue/crawlers" } ] }
• CloudWatch Logs の 保持期間が設定されていないグループの一覧を出す方法 • aws logs describe-log-groups |
jq -r '.logGroups | map(select(.retentionInDays == null or .retentionInDays == "")) | sort_by(.storedBytes) | .[] | [.logGroupName, .logGroupClass, .retentionInDays, .storedBytes] | @csv' 明日みんなに使ってほしいサンプル "/aws/codebuild/xxxxx", "STANDARD", , 86 "/aws/lambda/yyyyy", "STANDARD", , 106 "/aws/OpenSearchService/domains/zzzzz/search-logs", "STANDARD", , 239 ︙ "/aws/lambda/aaaaa", "STANDARD", , 510708032 "/aws/lambda/bbbbb", "STANDARD", , 521204122 "/aws/lambda/ccccc", "STANDARD", , 532498400
ご清聴ありがとうございました!