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

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

使用 Amazon CloudTrail 对 Step Functions 进行日志记录

Step Functions 与 Amazon CloudTrail 集成,后者是在 Step Functions 中提供用户、角色或Amazon服务所采取操作的记录的服务。CloudTrail 将对 Step Functions 的所有 API 调用均作为事件捕获,包括来自 Step Functions 控制台的调用和对 Step Functions API 的代码调用。

如果您创建跟踪记录,则可以使 CloudTrail 事件持续传送到 Amazon Simple Storage Service (Amazon S3) 存储桶(包括 Step Functions 事件)。如果您不配置跟踪,则仍可在 CloudTrail 控制台中的 Event history(事件历史记录) 中查看最新事件。

使用 CloudTrail 收集的信息,您可以确定向 Step Functions 发出了什么请求、发出请求的 IP 地址、何人发出的请求、请求的发出时间以及其他详细信息。

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

CloudTrail 中的 Step Functions 信息

在您创建 Amazon 账户时,将在该账户上启用 CloudTrail。当 Step Functions 中发生活动时,该活动将记录在 CloudTrail 事件中,并与其它 Amazon 服务事件一同保存在事件历史记录中。

您可以在 Amazon 账户中查看、搜索和下载最新事件。有关更多信息,请参阅使用 CloudTrail 事件历史记录查看事件

要持续记录 Amazon 账户中的事件(包括 Step Functions 的事件),请创建跟踪记录。通过跟踪,CloudTrail 可将日志文件传送至 Amazon S3 桶。预设情况下,在控制台中创建跟踪时,此跟踪应用于所有 Amazon 区域。此跟踪记录在 Amazon 分区中记录所有区域中的事件,并将日志文件传送至您指定的 Simple Storage Service(Amazon S3)桶。此外,您可以配置其它Amazon服务,进一步分析在 CloudTrail 日志中收集的事件数据并采取行动。

有关更多信息,请参阅下列内容:

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

  • 请求是使用根用户凭证还是 用户凭证发出的

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

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

有关更多信息,请参阅 CloudTrail userIdentity 元素

示例:Step Functions 日志文件条目

跟踪是一种配置,可用于将事件作为日志文件传送到您指定的 Amazon S3 桶。CloudTrail 日志文件包含一个或多个日志条目。一个事件表示来自任何源的一个请求,包括有关所请求的操作、操作的日期和时间、请求参数等方面的信息。CloudTrail 日志文件不是公用 API 调用的有序堆栈跟踪,因此它们不会按任何特定顺序显示。

CreateActivity

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了 CreateActivity 操作。

{ "eventVersion": "1.04", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJYDLDBVBI4EXAMPLE", "arn": "arn:aws:iam::123456789012:user/test-user", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "test-user" }, "eventTime": "2016-10-28T01:17:56Z", "eventSource": "states.amazonaws.com", "eventName": "CreateActivity", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "Amazon Internal", "requestParameters": { "name": "OtherActivityPrefix.2016-10-27-18-16-56.894c791e-2ced-4cf4-8523-376469410c25" }, "responseElements": { "activityArn": "arn:aws:states:us-east-1:123456789012:activity:OtherActivityPrefix.2016-10-27-18-16-56.894c791e-2ced-4cf4-8523-376469410c25", "creationDate": "Oct 28, 2016 1:17:56 AM" }, "requestID": "37c67602-9cac-11e6-aed5-5b57d226e9ef", "eventID": "dc3becef-d06d-49bf-bc93-9b76b5f00774", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

CreateStateMachine

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了 CreateStateMachine 操作。

{ "eventVersion": "1.04", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJYDLDBVBI4EXAMPLE", "arn": "arn:aws:iam::123456789012:user/test-user", "accountId": "123456789012", "accessKeyId": "AKIAJL5C75K4ZEXAMPLE", "userName": "test-user" }, "eventTime": "2016-10-28T01:18:07Z", "eventSource": "states.amazonaws.com", "eventName": "CreateStateMachine", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "Amazon Internal", "requestParameters": { "name": "testUser.2016-10-27-18-17-06.bd144e18-0437-476e-9bb", "roleArn": "arn:aws:iam::123456789012:role/graphene/tests/graphene-execution-role", "definition": "{ \"StartAt\": \"SinglePass\", \"States\": { \"SinglePass\": { \"Type\": \"Pass\", \"End\": true } }}" }, "responseElements": { "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:testUser.2016-10-27-18-17-06.bd144e18-0437-476e-9bb", "creationDate": "Oct 28, 2016 1:18:07 AM" }, "requestID": "3da6370c-9cac-11e6-aed5-5b57d226e9ef", "eventID": "84a0441d-fa06-4691-a60a-aab9e46d689c", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

DeleteActivity

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了 DeleteActivity 操作。

{ "eventVersion": "1.04", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJYDLDBVBI4EXAMPLE", "arn": "arn:aws:iam::123456789012:user/test-user", "accountId": "123456789012", "accessKeyId": "AKIAJL5C75K4ZEXAMPLE", "userName": "test-user" }, "eventTime": "2016-10-28T01:18:27Z", "eventSource": "states.amazonaws.com", "eventName": "DeleteActivity", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "Amazon Internal", "requestParameters": { "activityArn": "arn:aws:states:us-east-1:123456789012:activity:testUser.2016-10-27-18-11-35.f017c391-9363-481a-be2e-" }, "responseElements": null, "requestID": "490374ea-9cac-11e6-aed5-5b57d226e9ef", "eventID": "e5eb9a3d-13bc-4fa1-9531-232d1914d263", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

DeleteStateMachine

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了 DeleteStateMachine 操作。

{ "eventVersion": "1.04", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJABK5MNKNAEXAMPLE", "arn": "arn:aws:iam::123456789012:user/graphene/tests/test-user", "accountId": "123456789012", "accessKeyId": "AKIAJA2ELRVCPEXAMPLE", "userName": "test-user" }, "eventTime": "2016-10-28T01:17:37Z", "eventSource": "states.amazonaws.com", "eventName": "DeleteStateMachine", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "Amazon Internal", "errorCode": "AccessDenied", "errorMessage": "User: arn:aws:iam::123456789012:user/graphene/tests/test-user is not authorized to perform: states:DeleteStateMachine on resource: arn:aws:states:us-east-1:123456789012:stateMachine:testUser.2016-10-27-18-16-38.ec6e261f-1323-4555-9fa", "requestParameters": null, "responseElements": null, "requestID": "2cf23f3c-9cac-11e6-aed5-5b57d226e9ef", "eventID": "4a622d5c-e9cf-4051-90f2-4cdb69792cd8", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

StartExecution

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了 StartExecution 操作。

{ "eventVersion": "1.04", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJYDLDBVBI4EXAMPLE", "arn": "arn:aws:iam::123456789012:user/test-user", "accountId": "123456789012", "accessKeyId": "AKIAJL5C75K4ZEXAMPLE", "userName": "test-user" }, "eventTime": "2016-10-28T01:17:25Z", "eventSource": "states.amazonaws.com", "eventName": "StartExecution", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "Amazon Internal", "requestParameters": { "input": "{}", "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:testUser.2016-10-27-18-16-26.482bea32-560f-4a36-bd", "name": "testUser.2016-10-27-18-16-26.6e229586-3698-4ce5-8d" }, "responseElements": { "startDate": "Oct 28, 2016 1:17:25 AM", "executionArn": "arn:aws:states:us-east-1:123456789012:execution:testUser.2016-10-27-18-16-26.482bea32-560f-4a36-bd:testUser.2016-10-27-18-16-26.6e229586-3698-4ce5-8d" }, "requestID": "264c6f08-9cac-11e6-aed5-5b57d226e9ef", "eventID": "30a20c8e-a3a1-4b07-9139-cd9cd73b5eb8", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

StopExecution

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了 StopExecution 操作。

{ "eventVersion": "1.04", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJYDLDBVBI4EXAMPLE", "arn": "arn:aws:iam::123456789012:user/test-user", "accountId": "123456789012", "accessKeyId": "AKIAJL5C75K4ZEXAMPLE", "userName": "test-user" }, "eventTime": "2016-10-28T01:18:20Z", "eventSource": "states.amazonaws.com", "eventName": "StopExecution", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "Amazon Internal", "requestParameters": { "executionArn": "arn:aws:states:us-east-1:123456789012:execution:testUser.2016-10-27-18-17-00.337b3344-83:testUser.2016-10-27-18-17-00.3a0801c5-37" }, "responseElements": { "stopDate": "Oct 28, 2016 1:18:20 AM" }, "requestID": "4567625b-9cac-11e6-aed5-5b57d226e9ef", "eventID": "e658c743-c537-459a-aea7-dafb83c18c53", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }