Logging AWS AppSync API 呼叫 AWS CloudTrail - AWS AppSync GraphQL

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

Logging AWS AppSync API 呼叫 AWS CloudTrail

AWS AppSync 已與 整合 AWS CloudTrail,此服務提供使用者、角色或服務 AWS in AWS AppSync 所採取動作的記錄。CloudTrail 會將 AWS AppSync 的 API 呼叫擷取為事件。擷取的呼叫包括來自 AWS AppSync 主控台的呼叫,以及對 AWS AppSync API 操作的程式碼呼叫。如果您建立追蹤,您可以啟用 CloudTrail 事件持續交付至 Amazon S3 儲存貯體,包括 AWS AppSync 的事件。即使您未設定追蹤,依然可以透過 CloudTrail 主控台中的事件歷史記錄檢視最新事件。您可以使用 CloudTrail 收集的資訊,判斷對 AWS AppSync 提出的請求、提出請求的 IP 地址、提出請求的人員、提出請求的時間,以及其他詳細資訊。

若要進一步了解 CloudTrail,請參閱「AWS CloudTrail 使用者指南」

CloudTrail 中的AWS AppSync 資訊

當您建立 AWS 帳戶時,會在您的帳戶上啟用 CloudTrail。當活動在 AWS AppSync 中發生時,該活動會記錄於 CloudTrail 事件,以及事件歷史記錄中的其他服務 AWS 事件。您可以在 AWS 帳戶中檢視、搜尋和下載最近的事件。如需詳細資訊,請參閱「使用 CloudTrail 事件歷史記錄檢視事件」

若要持續記錄您 AWS 帳戶中的事件,包括 for AWS AppSync 的事件,請建立追蹤。線索能讓 CloudTrail 將日誌檔案交付至 Amazon S3 儲存貯體。根據預設,當您在主控台中建立追蹤時,追蹤會套用至所有 AWS 區域。追蹤會記錄 AWS 分割區中所有 區域的事件,並將日誌檔案交付至您指定的 Amazon S3 儲存貯體。此外,您可以設定其他 AWS 服務,以進一步分析 CloudTrail 日誌中收集的事件資料並對其採取行動。如需詳細資訊,請參閱下列內容:

AWS AppSync 支援記錄透過 AWS AppSync API 進行的呼叫。目前, AWS AppSync 不會將對 APIs呼叫以及對解析程式的呼叫記錄到 CloudTrail。

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

  • 請求是使用根還是 AWS Identity and Access Management (IAM) 使用者登入資料提出。

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

  • 請求是否由其他 AWS 服務提出。

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

Understanding AWS AppSync 日誌檔案項目

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

下列範例顯示 CloudTrail 日誌項目,示範透過 AWS AppSync 主控台執行GetGraphqlApi的動作:

{ "eventVersion": "1.08", "userIdentity": { "type": "AssumedRole", "principalId": "ABCDEFXAMPLEPRINCIPAL:nikkiwolf", "arn": "arn:aws:sts::111122223333:assumed-role/admin/nikkiwolf", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AIDAJ45Q7YFFAREXAMPLE", "arn": "arn:aws:iam::111122223333:role/admin", "accountId": "111122223333", "userName": "admin" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-03-12T22:41:48Z" } } }, "eventTime": "2021-03-12T22:46:18Z", "eventSource": "appsync.amazonaws.com", "eventName": "GetGraphqlApi", "awsRegion": "us-west-2", "sourceIPAddress": "203.0.113.69", "userAgent": "aws-internal/3 aws-sdk-java/1.11.942 Linux/4.9.230-0.1.ac.223.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.282-b08 java/1.8.0_282 vendor/Oracle_Corporation", "requestParameters": { "apiId": "xhxt3typtfnmidkhcexampleid" }, "responseElements": null, "requestID": "2fc43a35-a552-4b5d-be6e-12553a03dd12", "eventID": "b95b0ad9-8c71-4252-a2ec-5dc2fe5f8ae8", "readOnly": true, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "111122223333" }

下列範例顯示 CloudTrail 日誌項目,示範透過 執行CreateApikey的動作 AWS CLI:

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "ABCDEFXAMPLEPRINCIPAL", "arn": "arn:aws:iam::111122223333:user/nikkiwolf", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "nikkiwolf" }, "eventTime": "2021-03-12T22:49:10Z", "eventSource": "appsync.amazonaws.com", "eventName": "CreateApiKey", "awsRegion": "us-west-2", "sourceIPAddress": "203.0.113.69", "userAgent": "aws-cli/2.0.11 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev15", "requestParameters": { "apiId": "xhxt3typtfnmidkhcexampleid" }, "responseElements": { "apiKey": { "id": "***", "expires": 1616191200, "deletes": 1621375200 } }, "requestID": "e152190e-04ba-4d0a-ae7b-6bfc0bcea6af", "eventID": "ba3f39e0-9d87-41c5-abbb-2000abcb6013", "readOnly": false, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "111122223333" }