使用 AWS CloudTrail 來 Amplify API 呼叫 - AWS Amplify

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

使用 AWS CloudTrail 來 Amplify API 呼叫

AWS Amplify 整合了 AWS CloudTrail,後者是一項服務,可提供由使用者、角色或 AWS 服務在 Alty 中所採取動作的記錄。CloudTrail 會將「Amplify」的所有 API 呼叫擷取為事件。擷取的呼叫包括從 Amplify 主控台進行的呼叫,以及對 Amplify API 操作的程式碼呼叫。如果您建立線索,就可以將 CloudTrail 事件持續交付至 Amazon S3 儲存貯體,包括 AlAmplify 的事件。如果您不設定追蹤記錄,仍然可以透過 CloudTrail 主控台中的 Event history (事件歷史記錄) 檢視最新的事件。您可以利用 CloudTrail 所收集的資訊來判斷向 Amplify 發出的請求,以及發出請求的 IP 地址、人員、時間和其他詳細資訊。

若要進一步了解 CloudTrail,請參閱 AWS CloudTrail User Guide

將 CloudTrail 中的資訊 Amplify

依預設,系統會在您的 AWS 帳戶中啟用 CloudTrail。此外,Alty 發生活動時,系 Amplify 便會將該活動記錄至 CloudTrail 事件,並將其他 AWS 服務事件記錄到事件歷史記錄。您可以檢視、搜尋和下載 AWS 帳戶的最新事件。如需詳細資訊,請參閱「」使用 CloudTrail 事件歷史記錄檢視事件中的AWS CloudTrail 使用者指南

如需 AWS 帳戶中正在進行事件的記錄 (包括 AltiAmplify 件),請建立追蹤。線索可讓 CloudTrail 將日誌檔案交付到 Amazon S3 儲存貯體。根據預設,當您在主控台建立追蹤記錄時,追蹤記錄會套用到所有 AWS 區域。該追蹤會記錄來自 AWS 分割區中所有區域的事件,並將日誌檔案交付到您指定的 Amazon S3 儲存貯體。此外,您可以設定其他 AWS 服務,以進一步分析和處理 CloudTrail 日誌中所收集的事件資料。如需詳細資訊,請參閱AWS CloudTrail 使用者指南

所有 Amplify 操作都是由 CloudTrail 記錄,並記錄在中。AWS Amplify 主控台 API 參考,AWS Amplify 管理員 UI API 參考。例如,呼叫至CreateAppDeleteAppDeleteBackendEnvironment操作會在 CloudTrail 日誌檔案中產生項目。

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

  • 該請求是否透過根或 AWS Identity and Access Management (IAM) 使用者登入資料所提出。

  • 該請求是否透過特定角色或聯合身分使用者的暫時安全登入資料提出。

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

如需詳細資訊,請參閲 。CloudTrail userIdentity 元素中的AWS CloudTrail 使用者指南

了解 Amplify 日誌檔案項目

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

以下範例顯示的是展示 Amplify 主控台 API 參考的 CloudTrail 日誌項目DeleteBackendEnvironmentoperation.

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::444455556666:user/Mary_Major", "accountId": "444455556666", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::444455556666:user/Mary_Major", "accountId": "444455556666", "userName": "Mary_Major" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-01-12T00:28:50Z" } }, "invokedBy": "apigateway.amazonaws.com" }, "eventTime": "2021-01-12T00:31:08Z", "eventSource": "amplify.amazonaws.com", "eventName": "DeleteBackendEnvironment", "awsRegion": "us-west-2", "sourceIPAddress": "apigateway.amazonaws.com", "userAgent": "apigateway.amazonaws.com", "requestParameters": { "environmentName": "staging", "appId": "d3lap6vexample" }, "responseElements": { "backendEnvironment": { "backendEnvironmentArn": "arn:aws:amplify:us-west-2:444455556666:apps/d3lap6vexample/backendenvironments/staging", "createTime": 1610086829.109, "deploymentArtifacts": "amplify-amplify9b7cd3example-staging-62027-deployment", "environmentName": "staging", "stackName": "amplify-amplify9b7cd3example-staging-62027", "updateTime": 1610086829.109 } }, "requestID": "1135382e-f832-45ba-ae53-f7ffbexample", "eventID": "cebab152-deb6-42e1-bd1f-d05b6example", "readOnly": false, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "444455556666" }

以下範例顯示的是展示 AWS Amplify 主控台 API 參考的 CloudTrail 日誌項目ListAppsoperation.

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::444455556666:user/Mary_Major", "accountId": "444455556666", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-01-12T05:48:10Z" } } }, "eventTime": "2021-01-12T06:47:29Z", "eventSource": "amplify.amazonaws.com", "eventName": "ListApps", "awsRegion": "us-west-2", "sourceIPAddress": "192.0.2.255", "userAgent": "aws-internal/3 aws-sdk-java/1.11.898 Linux/4.9.230-0.1.ac.223.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.275-b01 java/1.8.0_275 vendor/Oracle_Corporation", "requestParameters": { "maxResults": "100" }, "responseElements": null, "requestID": "1c026d0b-3397-405a-95aa-aa43aexample", "eventID": "c5fca3fb-d148-4fa1-ba22-5fa63example", "readOnly": true, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "444455556666" }

以下範例顯示的是展示 AWS Amplify 管理 UI API 參考的 CloudTrail 日誌項目ListBackendJobsoperation.

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::444455556666:user/Mary_Major", "accountId": "444455556666", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-01-13T00:47:25Z" } } }, "eventTime": "2021-01-13T01:15:43Z", "eventSource": "amplifybackend.amazonaws.com", "eventName": "ListBackendJobs", "awsRegion": "us-west-2", "sourceIPAddress": "192.0.2.255", "userAgent": "aws-internal/3 aws-sdk-java/1.11.898 Linux/4.9.230-0.1.ac.223.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.275-b01 java/1.8.0_275 vendor/Oracle_Corporation", "requestParameters": { "appId": "d23mv2oexample", "backendEnvironmentName": "staging" }, "responseElements": { "jobs": [ { "appId": "d23mv2oexample", "backendEnvironmentName": "staging", "jobId": "ed63e9b2-dd1b-4bf2-895b-3d5dcexample", "operation": "CreateBackendAuth", "status": "COMPLETED", "createTime": "1610499932490", "updateTime": "1610500140053" }, { "appId": "d23mv2oexample", "backendEnvironmentName": "staging", "jobId": "06904b10-a795-49c1-92b7-185dfexample", "operation": "CreateBackend", "status": "COMPLETED", "createTime": "1610499657938", "updateTime": "1610499704458" } ], "appId": "d23mv2oexample", "backendEnvironmentName": "staging" }, "requestID": "7adfabd6-98d5-4b11-bd39-c7deaexample", "eventID": "68769310-c96c-4789-a6bb-68b52example", "readOnly": false, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "444455556666" }