Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Trusted Advisor の対応推奨項目の diff をとる

Avatar for Mai Aisaka Mai Aisaka
January 30, 2025
330

Trusted Advisor の対応推奨項目の diff をとる

Trusted Advisor つかってますか?週次でのチェックにつかえそうなdiff取る手段をまとめてみました!

Avatar for Mai Aisaka

Mai Aisaka

January 30, 2025
Tweet

Transcript

  1. ©iCARE Co.,Ltd
 自己紹介 • あいさか (@mist_dev) • iCARE SRE 2年生

    • Ruby💎とビール🍺が好き ◦ 日本のクラフトビールが好き • 好きなクラフトビール ◦ 熊本の天草ソナービール🍺 ◦ フルーツスムージーなビールがおいしい
  2. ©iCARE Co.,Ltd
 きょうの話 • Trusted Advisor つかってますか? ◦ AWS 的な構成最適解をチェックして教えてくれる

    ▪ S3 のブロックパブリックアクセスちゃんと有効にしてる?とか ▪ RDS のバックアップちゃんと取ってる?とか • うちのチームでは週一で項目のチェックをしています ◦ AWS SDK for Ruby v3 で取得し diff を取っています
  3. ©iCARE Co.,Ltd
 • region は us-east-1 に設定する 準備 require "aws-sdk"

    aws_profile_name = ARGV[0] client = Aws::TrustedAdvisor::Client.new( region: 'us-east-1', profile: aws_profile_name )
  4. ©iCARE Co.,Ltd
 • チェックが必要な項目をレベル関係なく全件取得する list_checks で対応を要する項目を取得 checks = [] checks_next_token

    = nil loop do options = { language: "ja", max_results: 200, next_token: checks_next_token }.compact results = client. list_checks(options) checks_next_token = results.next_token checks << results.check_summaries break if checks_next_token.nil? end
  5. ©iCARE Co.,Ltd
 list_recommendations で対応を要する項目を取得 • マネジメントコンソールの赤い(error)実施推奨項目を取得する recommends = [] recommends_next_token

    = nil loop do options = { status: "error", next_token: recommends_next_token }.compact results = client. list_recommendations(options) recommends_next_token = results.next_token recommends << results.recommendation_summaries break if recommends_next_token.nil? end
  6. ©iCARE Co.,Ltd
 取得した結果をマージ • 取得した結果をマージし、error項目のタイトルだけをresultとして抽出する ◦ 結果は arn で突き合わせる result

    = recommends.flatten.filter_map do |recommend| check = checks.flatten.find { |check| recommend.check_arn == "arn:aws:trustedadvisor:::check/#{check.id}" } check if check && recommend.resources_aggregates.error_count > 0 end