使用 AWS CloudTrail 記錄 AWS CodeStar Notifications 通知 API 呼叫 - 開發人員工具主控台

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

使用 AWS CloudTrail 記錄 AWS CodeStar Notifications 通知 API 呼叫

AWS CodeStar Notifications 與 AWS CloudTrail 整合,該服務提供由使用者、角色或 AWS 服務所採取行動的記錄。CloudTrail 會擷取通知的 API 呼叫當作事件。擷取的呼叫包括從開發人員工具主控台進行的呼叫,以及對AWS CodeStar Notifications API 作業的程式碼呼叫。如果您建立追蹤記錄,就可以將 CloudTrail 事件持續交付到 Amazon S3 儲存貯體,包括通知的事件。即使您未設定追蹤,依然可以透過 CloudTrail 主控台中的 Event history (事件歷史記錄) 檢視最新事件。您可利用 CloudTrail 所收集的資訊來判斷向 AWS CodeStar Notifications 發出的請求,以及發出請求的 IP 地址、人員、時間和其他詳細資訊。

如需詳細資訊,請參閱《AWS CloudTrail 使用者指南》。

CloudTrail 中的 AWS CodeStar Notifications 資訊

當您建立帳戶時,系統即會在 AWS 帳戶 中啟用 CloudTrail。當 AWS CodeStar Notifications 中發生活動時,該活動會記錄在 CloudTrail 事件中,其他 AWS 服務事件則記錄於 Event history (事件歷程記錄) 中。您可以檢視、搜尋和下載 AWS 帳戶 的最新事件。如需詳細資訊,請參閱使用 CloudTrail 事件歷史記錄檢視事件

若要持續記錄 AWS 帳戶 的事件 (包括 AWS CodeStar Notifications 事件),請建立追蹤記錄。追蹤能讓 CloudTrail 將日誌檔交付至 Amazon S3 儲存貯體。依預設,當您在主控台中建立追蹤時,該追蹤會套用至所有的 AWS 區域。該追蹤會記錄來自 AWS 分割區中所有區域的事件,並將日誌檔案交付到您指定的 Amazon S3 儲存貯體。此外,您可以設定其他 AWS 服務,以進一步分析和處理 CloudTrail 日誌中所收集的事件資料。如需詳細資訊,請參閱下列內容:

CloudTrail 會記錄所有 AWS CodeStar Notifications 動作,並記載於 AWS CodeStar Notifications API 參考中。例如,對 CreateNotificationRuleSubscribeListEventTypes 動作發出的呼叫會在 CloudTrail 記錄檔案中產生項目。

每一筆事件或日誌項目都會包含產生請求者的資訊。身分資訊可協助您判斷下列事項:

  • 該請求是否透過根或 AWS Identity and Access Management (IAM) 使用者憑證來提出。

  • 提出該請求時,是否使用了特定角色或聯合身分使用者的暫時安全憑證。

  • 該請求是否由另一項 AWS 服務提出。

如需詳細資訊,請參閱 CloudTrail userIdentity 元素

了解 日誌檔案項目

追蹤是一種組態,可讓事件以日誌檔案的形式交付至您指定的 Amazon S3 儲存貯體。CloudTrail 日誌檔案包含一或多個日誌項目。一個事件為任何來源提出的單一請求,並包含請求動作、請求的日期和時間、請求參數等資訊。CloudTrail 日誌檔並非依公有 API 呼叫的堆疊追蹤排序,因此不會以任何特定順序出現。

以下範例顯示的 CloudTrail 日誌項目示範如何建立通知規則,包括 CreateNotificationRuleSubscribe 動作。

注意

通知日誌檔案項目中的某些事件可能來自服務連結角色 AWSServiceRoleForCodeStarNotifications。

{ "eventVersion": "1.05", "userIdentity": { "type":"IAMUser", "principalId":"AIDACKCEVSQ6C2EXAMPLE", "arn":"arn:aws:iam::123456789012:user/Mary_Major", "accountId":"123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName":"Mary_Major" }, "eventTime": "2019-10-07T21:34:41Z", "eventSource": "events.amazonaws.com", "eventName": "CreateNotificationRule", "awsRegion": "us-east-1", "sourceIPAddress": "codestar-notifications.amazonaws.com", "userAgent": "codestar-notifications.amazonaws.com", "requestParameters": { "description": "This rule is used to route CodeBuild, CodeCommit, CodePipeline, and other Developer Tools notifications to AWS CodeStar Notifications", "name": "awscodestarnotifications-rule", "eventPattern": "{\"source\":[\"aws.codebuild\",\"aws.codecommit\",\"aws.codepipeline\"]}" }, "responseElements": { "ruleArn": "arn:aws:events:us-east-1:123456789012:rule/awscodestarnotifications-rule" }, "requestID": "ff1f309a-EXAMPLE", "eventID": "93c82b07-EXAMPLE", "eventType": "AwsApiCall", "apiVersion": "2015-10-07", "recipientAccountId": "123456789012" }
{ "eventVersion": "1.05", "userIdentity": { "type":"IAMUser", "principalId":"AIDACKCEVSQ6C2EXAMPLE", "arn":"arn:aws:iam::123456789012:user/Mary_Major", "accountId":"123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName":"Mary_Major" }, "eventTime": "2019-10-07T21:34:41Z", "eventSource": "events.amazonaws.com", "eventName": "Subscribe", "awsRegion": "us-east-1", "sourceIPAddress": "codestar-notifications.amazonaws.com", "userAgent": "codestar-notifications.amazonaws.com", "requestParameters": { "targets": [ { "arn": "arn:aws:codestar-notifications:us-east-1:::", "id": "codestar-notifications-events-target" } ], "rule": "awscodestarnotifications-rule" }, "responseElements": { "failedEntryCount": 0, "failedEntries": [] }, "requestID": "9466cbda-EXAMPLE", "eventID": "2f79fdad-EXAMPLE", "eventType": "AwsApiCall", "apiVersion": "2015-10-07", "recipientAccountId": "123456789012" }