1
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?

More than 3 years have passed since last update.

Athenaを使ってCloudTrailログから、APIコールをカウントする

Last updated at Posted at 2020-07-16
  • AWSにて特定のAPI呼び出しで、エラーの発生が増えてきたので、その調査の覚書

指定したAPI呼び出しの件数

SELECT eventSource, COUNT(*) AS count
FROM "$DBNAME"."$TABLENAME"
WHERE eventName='$EVENTNAME'
AND eventTime > '2020-03-01T00:00:00Z'
GROUP BY DATE_FORMAT(from_iso8601_timestamp(eventTime), '%Y-%m-%d');

指定したAPIの日別の呼び出し件数

SELECT DATE_FORMAT(from_iso8601_timestamp(eventTime), '%Y-%m-%d') AS time, COUNT(*) AS count
FROM "$DBNAME"."$TABLENAME"
WHERE eventName='$EVENTNAME'
AND eventTime > '2020-03-01T00:00:00Z'
GROUP BY DATE_FORMAT(from_iso8601_timestamp(eventTime), '%Y-%m-%d');

指定したAPIと呼び出し元の日別の呼び出し件数

SELECT DATE_FORMAT(from_iso8601_timestamp(eventTime), '%Y-%m-%d') AS time, eventSource, userAgent, COUNT(*) as Count
FROM "$DBNAME"."$TABLENAME"
WHERE eventName='$EVENTNAME'
AND eventTime > '2020-03-01T00:00:00Z'
GROUP BY DATE_FORMAT(from_iso8601_timestamp(eventTime), '%Y-%m-%d'), eventSource, userAgent;

備考

  • S3上のCloudTrailログが多いと、クエリ実行時にAtheanのコスト増加およびTimeoutでになってしまうので、Athenaのテーブル作成の際に、ディレクトリを掘り下げて作成する
  • CloudTrailをAthenaで分析する際のテーブル作成は、CloudTrail上から(テーブル作成のための)クエリの生成および実行ができる
1
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
1
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?