使用 Amazon CloudTrail 记录 Amazon AppSync API 调用 - Amazon AppSync
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon CloudTrail 记录 Amazon AppSync API 调用

Amazon AppSync 与 Amazon CloudTrail 集成,后者是在 Amazon AppSync 中记录用户、角色或 Amazon 服务所执行操作的服务。CloudTrail 将 Amazon AppSync 的所有 API 调用作为事件捕获。捕获的调用包含来自 Amazon AppSync 控制台和来自对 Amazon AppSync API 的代码调用的调用。您可以使用 CloudTrail 收集的信息确定向 Amazon AppSync 发出的请求、请求者的 IP 地址、发出请求的人、发出请求的时间以及其他详细信息。

您可以创建跟踪以将 CloudTrail 事件持续传送到 Amazon Simple Storage Service (Amazon S3) 存储桶,包括 Amazon AppSync 事件。如果您未配置跟踪,您仍然可以在 CloudTrail 控制台中查看最新事件。

重要

当前不会记录所有 GraphQL 操作。AppSync 不会将查询和变量操作记录到 CloudTrail 中。

有关 CloudTrail 的更多信息,请参阅《Amazon CloudTrail 用户指南》。

CloudTrail 中的 Amazon AppSync 信息

在您创建 Amazon 账户时,将在该账户上启用 CloudTrail。在 CloudTrail 控制台的事件历史记录中,可以查看、搜索和下载您的 Amazon 账户中的最近事件。有关更多信息,请参阅 Amazon CloudTrail 用户指南中的使用 CloudTrail 事件历史记录查看事件

要持续记录 Amazon 账户中的事件(包括 Amazon AppSync 的事件),请创建跟踪。预设情况下,在控制台中创建跟踪时,此跟踪应用于所有 Amazon 区域。此跟踪记录在 Amazon 分区中记录所有区域中的事件,并将日志文件传送至您指定的 Amazon S3 存储桶。此外,您可以配置其他Amazon服务,进一步分析在 CloudTrail 日志中收集的事件数据并采取行动。有关更多信息,请参阅 Amazon CloudTrail 用户指南中的以下内容:

CloudTrail 记录所有 Amazon AppSync API 操作。例如,对 CreateGraphqlApiCreateDataSourceListResolvers API 的调用在 CloudTrail 日志文件中生成条目。在 Amazon AppSync API Reference 中介绍了这些操作和其他操作。

每个事件或日志条目都包含有关生成请求的人员信息。身份信息可以帮助您确定:

  • 请求是使用根用户凭证还是 Amazon Identity and Access Management(IAM) 用户凭证发出的。

  • 请求是使用角色还是联合身份用户的临时安全凭证发出的。

  • 请求是否由其他Amazon服务发出。

有关更多信息,请参阅 Amazon CloudTrail 用户指南中的 CloudTrail userIdentity 元素

了解 Amazon AppSync 日志文件条目

CloudTrail 将事件作为包含一个或多个日志条目的日志文件提供。一个事件表示来自任何源的单个请求,并包括有关请求的操作、操作日期和时间、请求参数等信息。由于这些日志文件不是公有 API 调用的有序堆栈跟踪,因此,它们不会按任何特定顺序显示。

以下示例 CloudTrail 日志条目说明了 CreateApiKey 操作。

{ "Records": [{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "A1B2C3D4E5F6G7EXAMPLE", "arn": "arn:aws:iam::111122223333:user/Alice", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alice" }, "eventTime": "2018-01-31T21:49:09Z", "eventSource": "appsync.amazonaws.com", "eventName": "CreateApiKey", "awsRegion": "us-west-2", "sourceIPAddress": "192.2.0.1", "userAgent": "aws-cli/1.11.72 Python/2.7.11 Darwin/16.7.0 botocore/1.5.35", "requestParameters": { "apiId": "a1b2c3d4e5f6g7h8i9jexample" }, "responseElements": { "apiKey": { "id": "***", "expires": 1518037200000 } }, "requestID": "99999999-9999-9999-9999-999999999999", "eventID": "99999999-9999-9999-9999-999999999999", "readOnly": false, "eventType": "AwsApiCall", "recipientAccountId": "111122223333" } ] }

以下示例 CloudTrail 日志条目说明了 ListApiKeys 操作。

{ "Records": [{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "A1B2C3D4E5F6G7EXAMPLE", "arn": "arn:aws:iam::111122223333:user/Alice", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alice" }, "eventTime": "2018-01-31T21:49:09Z", "eventSource": "appsync.amazonaws.com", "eventName": "ListApiKeys", "awsRegion": "us-west-2", "sourceIPAddress": "192.2.0.1", "userAgent": "aws-cli/1.11.72 Python/2.7.11 Darwin/16.7.0 botocore/1.5.35", "requestParameters": { "apiId": "a1b2c3d4e5f6g7h8i9jexample" }, "responseElements": { "apiKeys": [ { "id": "***", "expires": 1517954400000 }, { "id": "***", "expires": 1518037200000 }, ] }, "requestID": "99999999-9999-9999-9999-999999999999", "eventID": "99999999-9999-9999-9999-999999999999", "readOnly": false, "eventType": "AwsApiCall", "recipientAccountId": "111122223333" } ] }

以下示例 CloudTrail 日志条目说明了 DeleteApiKey 操作。

{ "Records": [{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "A1B2C3D4E5F6G7EXAMPLE", "arn": "arn:aws:iam::111122223333:user/Alice", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alice" }, "eventTime": "2018-01-31T21:49:09Z", "eventSource": "appsync.amazonaws.com", "eventName": "DeleteApiKey", "awsRegion": "us-west-2", "sourceIPAddress": "192.2.0.1", "userAgent": "aws-cli/1.11.72 Python/2.7.11 Darwin/16.7.0 botocore/1.5.35", "requestParameters": { "id": "***", "apiId": "a1b2c3d4e5f6g7h8i9jexample" }, "responseElements": null, "requestID": "99999999-9999-9999-9999-999999999999", "eventID": "99999999-9999-9999-9999-999999999999", "readOnly": false, "eventType": "AwsApiCall", "recipientAccountId": "111122223333" } ] }