0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Security HubのFindings一括取得でTooManyRequestsExceptionが出た話

0
Posted at

みなさん、こんにちは!
AWS Security Hubで複数のコンプライアンス基準を有効化した状態でFindingsを一括取得しようとしたところ、TooManyRequestsExceptionが発生しました。
今回はその事象と、AWS_RETRY_MODE=adaptiveで解決した内容をお届けします。

はじめに

Security HubのGetFindings APIには、AWS公式仕様でレート制限が設けられています。

  • 3リクエスト/秒
  • バースト6

普段は意識することのない制限ですが、有効化する基準(スタンダード)の数が増えてFinding件数・ページ数が多くなると、この制限に引っかかることがあります。

今回はAWS向けのstandardsを9件新規に有効化し(元々有効だった2件と合わせて計11件)、CLIで全Findingsを取得しようとしたタイミングで発生しました。

事象

aws securityhub get-findingsコマンドを実行したところ、以下のエラーで処理が止まりました。

  • コマンド: aws securityhub get-findings --region ap-northeast-1 --output json > securityhub-findings-full-20260814.json
  • エラー: aws: [ERROR]: An error occurred (TooManyRequestsException) when calling the GetFindings operation (reached max retries: 2): Too Many Requests
  • 出力先ファイルのサイズは0バイトで、データは取得できていませんでした。

image.png
AWS CLIはデフォルトでもリトライ処理を行いますが、既定のリトライ回数(2回)では、standards9件分・大量ページのFinding取得に追いつきませんでした。

解決策

AWS CLIの環境変数を以下の2つに設定してから、同じコマンドを再実行しました。

  • AWS_RETRY_MODE=adaptive: リクエストのペースをAPI側のレート制限に合わせて自動調整するリトライモード
  • AWS_MAX_ATTEMPTS=15: 最大リトライ回数を15回に引き上げ
bash export AWSRETRYMODE=adaptive export AWSMAXATTEMPTS=15
aws securityhub get-findings --region ap-northeast-1 --output json > securityhub-findings-full-20260814.json 

再実行後は、エラーなく取得が完了しました。

  • securityhub-findings-full-20260814.json: 約48MB(50,811,669バイト)を正常に取得
  • CIS基準(v3.0.0)のみに絞ったFinding取得も、同じ設定で問題なく成功

image.png

おわりに

Security Hubで複数の基準を有効化した状態でFindingsを一括取得すると、GetFindingsAPIのレート制限(3リクエスト/秒)に引っかかりTooManyRequestsExceptionが発生することがあります。

対処法はAWS_RETRY_MODE=adaptiveとAWS_MAX_ATTEMPTSの環境変数を設定するだけで、取得コマンド自体を変更する必要はありませんでした。

同じ事象に遭遇した方の参考になれば幸いです。
最後までご覧いただきありがとうございました!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?