利用 Amazon CloudWatch 日誌洞察分析 Amazon Cognito CloudTrail 事件 - Amazon Cognito

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

利用 Amazon CloudWatch 日誌洞察分析 Amazon Cognito CloudTrail 事件

您可以使用 Amazon CloudWatch 日誌洞察來搜尋和分析您的 Amazon Cognito CloudTrail 事件。當您將追蹤設定為將事件傳送至 CloudWatch 記錄檔時,只 CloudTrail 會傳送符合追蹤設定的事件。

若要查詢或研究 Amazon Cognito CloudTrail 事件,請務必在 CloudTrail 主控台中選取追蹤設定中的管理事件選項,以便監控在 AWS 資源上執行的管理操作。想找出您帳戶中的錯誤、異常活動或異常使用者行為時,您可以選擇性選取追蹤設定中的 Insights 事件 選項。

Amazon Cognito 查詢範例

您可以在 Amazon CloudWatch 主控台中使用下列查詢。

一般查詢

尋找最近新增的 25 個日誌事件。

fields @timestamp, @message | sort @timestamp desc | limit 25 | filter eventSource = "cognito-idp.amazonaws.com"

取得最近新增的 25 個日誌事件 (包含例外狀況) 清單。

fields @timestamp, @message | sort @timestamp desc | limit 25 | filter eventSource = "cognito-idp.amazonaws.com" and @message like /Exception/

例外狀況和錯誤查詢

使用錯誤碼 NotAuthorizedException 及 Amazon Cognito 使用者集區 sub,尋找最近新增的 25 個日誌事件。

fields @timestamp, additionalEventData.sub as user | sort @timestamp desc | limit 25 | filter eventSource = "cognito-idp.amazonaws.com" and errorCode= "NotAuthorizedException"

使用 sourceIPAddress 和相應 eventName,尋找記錄數量。

filter eventSource = "cognito-idp.amazonaws.com" | stats count(*) by sourceIPAddress, eventName

尋找觸發 NotAuthorizedException 錯誤的前 25 個 IP 地址。

filter eventSource = "cognito-idp.amazonaws.com" and errorCode= "NotAuthorizedException" | stats count(*) as count by sourceIPAddress, eventName | sort count desc | limit 25

尋找呼叫的前 25 個 IP 位址ForgotPasswordAPI。

filter eventSource = "cognito-idp.amazonaws.com" and eventName = 'ForgotPassword' | stats count(*) as count by sourceIPAddress | sort count desc | limit 25