Amazon Simple Queue Service
开发人员指南
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

使用 AWS CloudTrail 对 Amazon SQS API 操作进行日志记录

Amazon SQS 与 CloudTrail 集成在一起,是一个用于捕获 Amazon SQS 或代表它在您的 AWS 账户中发出的 API 调用并将日志文件传递到指定的 Amazon S3 存储桶的服务。CloudTrail 捕获从 Amazon SQS 控制台或从 Amazon SQS API 发出的 API 调用。您可使用通过 CloudTrail 收集的信息来确定向 Amazon SQS 发出的请求、发出请求的源 IP 地址、发出请求的人以及发出请求的时间,等等。要了解有关 CloudTrail 的更多信息,包括如何对其进行配置和启用,请参阅 AWS CloudTrail User Guide

标准队列和 FIFO 队列支持 CloudTrail。

CloudTrail 中的 Amazon SQS 信息

在您的 AWS 账户中启用 CloudTrail 日志记录后,将在日志文件中跟踪对 Amazon SQS 操作执行的 API 调用。Amazon SQS 记录与其他 AWS 服务记录一起写入日志文件。CloudTrail 基于时间段和文件大小来确定何时创建新文件并向其写入内容。

支持以下操作:

每个日志条目都包含有关生成请求的人员的信息。日志中的用户身份信息有助于确定请求是由根或 IAM 用户凭证发出,通过某个角色或联合用户的临时安全凭证发出,还是由其他 AWS 服务发出。有关更多信息,请参阅 CloudTrail 事件参考中的 userIdentity 字段。

日志文件可以在存储桶中存储任意长时间,不过您也可以定义 Amazon S3 生命周期规则以自动存档或删除日志文件。

如果需要针对日志文件传输快速采取措施,可选择让 CloudTrail 在传输新日志文件时发布 Amazon SNS 通知。有关更多信息,请参阅为 CloudTrail 配置 Amazon SNS 通知

您还可以将来自多个 AWS 区域和多个 AWS 账户的 Amazon SQS 日志文件聚合到单个 Amazon S3 存储桶中。有关更多信息,请参阅接收来自多个区域的 CloudTrail 日志文件

了解 Amazon SQS 日志文件条目

CloudTrail 日志文件可包含一个或多个日志条目,每个条目由多个 JSON 格式的事件组成。一个日志条目表示来自任何源的一个请求,包括有关所请求的操作、所有参数以及操作的日期和时间等信息。日志条目不一定具有任何特定顺序。即,它们不是公共 API 调用的有序堆栈跟踪。

AddPermission

以下示例显示 AddPermission 的一个 CloudTrail 日志条目:

Copy
{ "Records": [ { "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice" }, "eventTime": "2014-07-16T00:44:19Z", "eventSource": "sqs.amazonaws.com", "eventName": "AddPermission", "awsRegion": "us-east-2", "sourceIPAddress": "192.0.2.0", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "actions": [ "SendMessage" ], "aWSAccountIds": [ "123456789012" ], "label": "label", "queueUrl": "http://test-sqs.amazon.com/123456789012/hello1" }, "responseElements": null, "requestID": "334ccccd-b9bb-50fa-abdb-80f274981d60", "eventID": "0552b000-09a3-47d6-a810-c5f9fd2534fe" } ] }

CreateQueue

以下示例显示 CreateQueue 的一个 CloudTrail 日志条目:

Copy
{ "Records": [ { "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice" }, "eventTime": "2014-07-16T00:42:42Z", "eventSource": "sqs.amazonaws.com", "eventName": "CreateQueue", "awsRegion": "us-east-2", "sourceIPAddress": "192.0.2.0", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "queueName": "hello1" }, "responseElements": { "queueUrl": "http://test-sqs.amazon.com/123456789012/hello1" }, "requestID": "49ebbdb7-5cd3-5323-8a00-f1889011fee9", "eventID": "68f4e71c-4f2f-4625-8378-130ac89660b1" } ] }

DeleteQueue

以下示例显示 DeleteQueue 的一个 CloudTrail 日志条目:

Copy
{ "Records": [ { "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice" }, "eventTime": "2014-07-16T00:44:47Z", "eventSource": "sqs.amazonaws.com", "eventName": "DeleteQueue", "awsRegion": "us-east-2", "sourceIPAddress": "192.0.2.0", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "queueUrl": "http://test-sqs.amazon.com/123456789012/hello1" }, "responseElements": null, "requestID": "e4c0cc05-4faa-51d5-aab2-803a8294388d", "eventID": "af1bb158-6443-4b4d-abfd-1b867280d964" } ] }

RemovePermission

以下示例显示 RemovePermission 的一个 CloudTrail 日志条目:

Copy
{ "Records": [ { "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice" }, "eventTime": "2014-07-16T00:44:36Z", "eventSource": "sqs.amazonaws.com", "eventName": "RemovePermission", "awsRegion": "us-east-2", "sourceIPAddress": "192.0.2.0", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "label": "label", "queueUrl": "http://test-sqs.amazon.com/123456789012/hello1" }, "responseElements": null, "requestID": "48178821-9c2b-5be0-88bf-c41e5118162a", "eventID": "fed8a623-3fe9-4e64-9543-586d9e500159" } ] }

SetQueueAttributes

以下示例显示 SetQueueAttributes 的一个 CloudTrail 日志条目:

Copy
{ "Records": [ { "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice" }, "eventTime": "2014-07-16T00:43:15Z", "eventSource": "sqs.amazonaws.com", "eventName": "SetQueueAttributes", "awsRegion": "us-east-2", "sourceIPAddress": "192.0.2.0", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "attributes": { "VisibilityTimeout": "100" }, "queueUrl": "http://test-sqs.amazon.com/123456789012/hello1" }, "responseElements": null, "requestID": "7f15d706-f3d7-5221-b9ca-9b393f349b79", "eventID": "8b6fb2dc-2661-49b1-b328-94317815088b" } ] }