使用记录亚马逊SQSAPI通话 Amazon CloudTrail - Amazon Simple Queue Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

使用记录亚马逊SQSAPI通话 Amazon CloudTrail

亚马逊SQS已与 Amazon CloudTrail 录制来自用户、角色或角色的 Amazon SQS 通话 Amazon 服务。 CloudTrail 捕获与亚马逊SQS标准和FIFO队列相关的API呼叫作为事件,包括通过亚马逊SQS控制台发起的交互以及通过调用 Ama SQS APIs zon 以编程方式发起的交互。

中的亚马逊SQS信息 CloudTrail

CloudTrail 创建时默认处于开启状态 Amazon account。当支持的 Amazon SQS 事件活动发生时,会将其与其他 CloudTrail 活动一起记录在事件中 Amazon 服务事件,在事件历史记录中。您可以查看、搜索和下载最近发生的事件 Amazon account。有关更多信息,请参阅《使用 CloudTrail 事件历史记录查看事件》Amazon CloudTrail 用户指南

调用队列管理操作(例如)的 Amazon SQS APIs AddPermission 被归类为管理事件,并且 CloudTrail 默认处于登录状态。Amazon SQS APIs 是在 Amazon SQS 队列上执行的大容量操作,例如SendMessage被归类为数据事件,在您选择使用 CloudTrail后记录下来。

使用 CloudTrail 收集到的信息,您可以识别向 Amazon 提出的特定请求SQSAPI、请求者的 IP 地址或身份,以及请求的日期和时间。如果您配置 CloudTrail 跟踪,则可以将 CloudTrail 事件持续传输到 Amazon S3 存储桶,并可选择传送到 Amazon CloudWatch Logs 和 Amazon EventBridge。如果未配置跟踪,则只能在 CloudTrail 控制台的事件中查看管理事件的事件历史记录。有关更多信息,请参阅《中的创建跟踪概述 Amazon CloudTrail 用户指南

中的管理活动 CloudTrail

Amazon 将以下API操作SQS记录为管理事件:

支持以下 SQS APIs Amazon 进行 CloudTrail日志记录:

中的数据事件 CloudTrail

数据事件提供有关在资源上或在资源中执行的资源操作的信息,例如向亚马逊SQS队列发送或接收亚马逊SQS消息。数据事件是指默认情况下 CloudTrail 不记录的大容量活动。您可以使用为SQS队列启用数据事件API操作日志记录 CloudTrail APIs。有关更多信息,请参阅中的记录数据事件 Amazon CloudTrail 用户指南

使用 CloudTrail,您可以使用高级事件选择器来决定记录和记录哪些亚马逊SQSAPI活动。要记录 Amazon SQS 数据事件,您必须包括资源类型AWS::SQS::Queue。设置完成后,您可以通过选择要记录的特定数据事件(例如使用 eventName 过滤器来跟踪 SendMessage 事件)来进一步调整日志记录首选项。有关更多信息,请参阅《》 中的 AdvancedEventSelector。Amazon CloudTrail API参考

亚马逊SQS数据事件:

记录数据事件将收取额外费用。有关更多信息,请参阅 Amazon CloudTrail定价

示例:Amazon 的 CloudTrail 管理事件 SQS

以下示例显示了支持的 CloudTrail 日志条目APIs:

AddPermission

以下示例显示了AddPermissionAPI呼叫的 CloudTrail 日志条目。

{ "Records": [ { "eventVersion": "1.06", "userIdentity": { "type": "IAMUser", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alice" }, "eventTime": "2018-06-28T22:23:46Z", "eventSource": "sqs.amazonaws.com", "eventName": "AddPermission", "awsRegion": "us-east-2", "sourceIPAddress": "203.0.113.0", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "actions": [ "SendMessage" ], "AWSAccountIds": [ "123456789012" ], "label": "MyLabel", "queueUrl": "https://sqs.us-east-2.amazon.com/123456789012/MyQueue" }, "responseElements": null, "requestID": "123abcde-f4gh-50ij-klmn-60o789012p30", "eventID": "0987g654-32f1-09e8-d765-c4f3fb2109fa" } ] }
CreateQueue

以下示例显示了CreateQueueAPI呼叫的 CloudTrail 日志条目。

{ "Records": [ { "eventVersion": "1.06", "userIdentity": { "type": "IAMUser", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Alejandro", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alejandro" }, "eventTime": "2018-06-28T22:23:46Z", "eventSource": "sqs.amazonaws.com", "eventName": "CreateQueue", "awsRegion": "us-east-2", "sourceIPAddress": "203.0.113.1", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "queueName": "MyQueue" }, "responseElements": { "queueUrl": "https://sqs.us-east-2.amazon.com/123456789012/MyQueue" }, "requestID": "123abcde-f4gh-50ij-klmn-60o789012p30", "eventID": "0987g654-32f1-09e8-d765-c4f3fb2109fa" } ] }
DeleteQueue

以下示例显示了DeleteQueueAPI呼叫的 CloudTrail 日志条目。

{ "Records": [ { "eventVersion": "1.06", "userIdentity": { "type": "IAMUser", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Carlos", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Carlos" }, "eventTime": "2018-06-28T22:23:46Z", "eventSource": "sqs.amazonaws.com", "eventName": "DeleteQueue", "awsRegion": "us-east-2", "sourceIPAddress": "203.0.113.2", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "queueUrl": "https://sqs.us-east-2.amazon.com/123456789012/MyQueue" }, "responseElements": null, "requestID": "123abcde-f4gh-50ij-klmn-60o789012p30", "eventID": "0987g654-32f1-09e8-d765-c4f3fb2109fa" } ] }
RemovePermission

以下示例显示了RemovePermissionAPI呼叫的 CloudTrail 日志条目。

{ "Records": [ { "eventVersion": "1.06", "userIdentity": { "type": "IAMUser", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Jane", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Jane" }, "eventTime": "2018-06-28T22:23:46Z", "eventSource": "sqs.amazonaws.com", "eventName": "RemovePermission", "awsRegion": "us-east-2", "sourceIPAddress": "203.0.113.3", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "label": "label", "queueUrl": "https://sqs.us-east-2.amazon.com/123456789012/MyQueue" }, "responseElements": null, "requestID": "123abcde-f4gh-50ij-klmn-60o789012p30", "eventID": "0987g654-32f1-09e8-d765-c4f3fb2109fa" } ] }
SetQueueAttributes

以下示例显示了以下内容的 CloudTrail 日志条目SetQueueAttributes

{ "Records": [ { "eventVersion": "1.06", "userIdentity": { "type": "IAMUser", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Maria", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Maria" }, "eventTime": "2018-06-28T22:23:46Z", "eventSource": "sqs.amazonaws.com", "eventName": "SetQueueAttributes", "awsRegion": "us-east-2", "sourceIPAddress": "203.0.113.4", "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", "requestParameters": { "attributes": { "VisibilityTimeout": "100" }, "queueUrl": "https://sqs.us-east-2.amazon.com/123456789012/MyQueue" }, "responseElements": null, "requestID": "123abcde-f4gh-50ij-klmn-60o789012p30", "eventID": "0987g654-32f1-09e8-d765-c4f3fb2109fa" } ] }

示例:Amazon CloudTrail 的数据事件 SQS

以下是特定于 Amazon SQS 数据 CloudTrail 事件的事件示例APIs:

SendMessage

以下示例显示了 CloudTrail 的数据事件SendMessage

{ "eventVersion": "1.09", "userIdentity": { "type": "AssumedRole", "principalId": "EXAMPLE_PRINCIPAL_ID", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed/SessionName", "accountId": "123456789012", "accessKeyId": "ACCESS_KEY_ID", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed", "accountId": "123456789012", "userName": "RoleToBeAssumed" }, "attributes": { "creationDate": "2023-11-07T22:13:06Z", "mfaAuthenticated": "false" } } }, "eventTime": "2023-11-07T23:59:11Z", "eventSource": "sqs.amazonaws.com", "eventName": "SendMessage", "awsRegion": "ap-southeast-4", "sourceIPAddress": "10.0.118.80", "userAgent": "aws-cli/1.29.16 md/Botocore#1.31.16 ua/2.0 os/linux#5.4.250-173.369.amzn2int.x86_64 md/arch#x86_64 lang/python#3.8.17 md/pyimpl#CPython cfg/retry-mode#legacy botocore/1.31.16", "requestParameters": { "queueUrl": "https://sqs.ap-southeast-4.amazonaws.com/123456789012/MyQueue", "messageBody": "HIDDEN_DUE_TO_SECURITY_REASONS", "messageDeduplicationId": "MsgDedupIdSdk1ae1958f2-bbe8-4442-83e7-4916e3b035aa", "messageGroupId": "MsgGroupIdSdk16" }, "responseElements": { "mD5OfMessageBody": "9a4e3f7a614d9dd9f8722092dbda17a2", "mD5OfMessageSystemAttributes": "f88f0587f951b7f5551f18ae699c3a9d", "messageId": "93bb6e2d-1090-416c-81b0-31eb1faa8cd8", "sequenceNumber": "18881790870905840128" }, "requestID": "c4584600-fe8a-5aa3-a5ba-1bc42f055fae", "eventID": "98c735d8-70e0-4644-9432-b6ced4d791b1", "readOnly": false, "resources": [ { "accountId": "123456789012", "type": "AWS::SQS::Queue", "ARN": "arn:aws:sqs:ap-southeast-4:123456789012:MyQueue" } ], "eventType": "AwsApiCall", "managementEvent": false, "recipientAccountId": "123456789012", "eventCategory": "Data", "tlsDetails": { "tlsVersion": "TLSv1.2", "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256", "clientProvidedHostHeader": "sqs.ap-southeast-4.amazonaws.com" }
ReceiveMessage

以下示例显示了 CloudTrail 的数据事件ReceiveMessage

{ "eventVersion": "1.09", "userIdentity": { "type": "AssumedRole", "principalId": "EXAMPLE_PRINCIPAL_ID", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed/SessionName", "accountId": "123456789012", "accessKeyId": "ACCESS_KEY_ID", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed", "accountId": "123456789012", "userName": "RoleToBeAssumed" }, "attributes": { "creationDate": "2023-11-07T22:13:06Z", "mfaAuthenticated": "false" } } }, "eventTime": "2023-11-07T23:59:24Z", "eventSource": "sqs.amazonaws.com", "eventName": "ReceiveMessage", "awsRegion": "ap-southeast-4", "sourceIPAddress": "10.0.118.80", "userAgent": "aws-cli/1.29.16 md/Botocore#1.31.16 ua/2.0 os/linux#5.4.250-173.369.amzn2int.x86_64 md/arch#x86_64 lang/python#3.8.17 md/pyimpl#CPython cfg/retry-mode#legacy botocore/1.31.16", "requestParameters": { "queueUrl": "https://sqs.ap-southeast-4.amazonaws.com/123456789012/MyQueue", "maxNumberOfMessages": 10 }, "responseElements": null, "requestID": "8b4d4643-8f49-52cd-a6e8-1b875ed54b99", "eventID": "f3f23ab7-b0a4-4b71-afc0-141209c49206", "readOnly": true, "resources": [ { "accountId": "123456789012", "type": "AWS::SQS::Queue", "ARN": "arn:aws:sqs:ap-southeast-4:123456789012:MyQueue" } ], "eventType": "AwsApiCall", "managementEvent": false, "recipientAccountId": "123456789012", "eventCategory": "Data", "tlsDetails": { "tlsVersion": "TLSv1.2", "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256", "clientProvidedHostHeader": "sqs.ap-southeast-4.amazonaws.com" } }
DeleteMessageBatch

以下示例显示了 CloudTrail 的数据事件DeleteMessageBatch

{ "eventVersion": "1.09", "userIdentity": { "type": "AssumedRole", "principalId": "EXAMPLE_PRINCIPAL_ID", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed/SessionName", "accountId": "123456789012", "accessKeyId": "ACCESS_KEY_ID", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed", "accountId": "123456789012", "userName": "RoleToBeAssumed" }, "attributes": { "creationDate": "2023-11-07T22:13:06Z", "mfaAuthenticated": "false" } } }, "eventTime": "2023-11-07T23:59:24Z", "eventSource": "sqs.amazonaws.com", "eventName": "DeleteMessageBatch", "awsRegion": "ap-southeast-4", "sourceIPAddress": "10.0.118.80", "userAgent": "aws-cli/1.29.16 md/Botocore#1.31.16 ua/2.0 os/linux#5.4.250-173.369.amzn2int.x86_64 md/arch#x86_64 lang/python#3.8.17 md/pyimpl#CPython cfg/retry-mode#legacy botocore/1.31.16", "requestParameters": { "queueUrl": "https://sqs.ap-southeast-4.amazonaws.com/123456789012/MyQueue", "entries": [ { "id": "0", "receiptHandle": "AQEBefxM1O4zyZGF87DehbRbmri91w2W7mMdD0GrBjQa8e/hpb4RbXHPZ9tLBVleECbChQIE5NtaDuoZhZPOkTy0eN46EyRR4jXDzE3AlkbPlX1mA9f2fUuTrXx8aeCoCA3I3woNg3fXXAoo5ctLgci0Z/hlLS94tjAZqV2krc4BaC2pYgjyHWcW019HwIV8T/bjNMIeZoQwOM5V+o9vHPfewz5QGr5SKpDo7uE7Umyk5n5CJZvcn1efp/mrwtaCIb9M7cCQUYcZm2ZmZDnIO9XpGTAi3m2dQ0M83pnNh0nvDfpkHpoa+hX1TrUmxCupCWHJwA8HFJ1O/CCJsodMNFthLBA9S57dkBZCsw41G8jAmgQ0MkvZ0UL5mg0OFQQd1Yrw0zvthjCgiwdzn0yXoMzxIZMBxkY14E4nVVZ7N5XEMtMmgxsI1XF/h8oRk2C7gByzg2kYJ0LnUvLJFT8DQE28JZppEC9klvrdR/BWiPT7asc=" } ] }, "responseElements": { "successful": [ { "id": "0" } ], "failed": [] }, "requestID": "fe423091-5642-5ba5-9256-6d5587de52f1", "eventID": "88c8020d-d769-4985-8ecb-ee0b59acc418", "readOnly": false, "resources": [ { "accountId": "123456789012", "type": "AWS::SQS::Queue", "ARN": "arn:aws:sqs:ap-southeast-4:123456789012:MyQueue" } ], "eventType": "AwsApiCall", "managementEvent": false, "recipientAccountId": "123456789012", "eventCategory": "Data", "tlsDetails": { "tlsVersion": "TLSv1.2", "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256", "clientProvidedHostHeader": "sqs.ap-southeast-4.amazonaws.com" } }
ChangeMessageVisibilityBatch

以下示例显示了 CloudTrail 的数据事件ChangeMessageVisibilityBatch

{ "eventVersion": "1.09", "userIdentity": { "type": "AssumedRole", "principalId": "EXAMPLE_PRINCIPAL_ID", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed/SessionName", "accountId": "123456789012", "accessKeyId": "ACCESS_KEY_ID", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AKIAI44QH8DHBEXAMPLE", "arn": "arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed", "accountId": "123456789012", "userName": "RoleToBeAssumed" }, "attributes": { "creationDate": "2023-11-07T22:13:06Z", "mfaAuthenticated": "false" } } }, "eventTime": "2023-11-07T23:59:01Z", "eventSource": "sqs.amazonaws.com", "eventName": "ChangeMessageVisibilityBatch", "awsRegion": "ap-southeast-4", "sourceIPAddress": "10.0.118.80", "userAgent": "aws-cli/1.29.16 md/Botocore#1.31.16 ua/2.0 os/linux#5.4.250-173.369.amzn2int.x86_64 md/arch#x86_64 lang/python#3.8.17 md/pyimpl#CPython cfg/retry-mode#legacy botocore/1.31.16", "requestParameters": { "visibilityTimeout": 0, "entries": [ { "id": "0", "receiptHandle": "AQEB2M5cVYg5gslhWME6537hdjcaPnOYPA5M0W460TTb0DzPle631yPWm8qxd4O1hDj/B4ntTMnsgBTa95t14tNx7Vn96jKJ5rIoZ7iI8TRmkT1caKodKIPs8w9yndZq50c2FPQxtyH+2L3UHf/abV3szqVWXOLZR4PwX8zZkWVQGNCNnY2q2lGCG586F8QwvrOFYoXNwB8ymd1t77e1PDPknq1Io3JFuzkEsndkkETy4fV1QqVCSTR1izaTKF44f/l5PHX17nXxaC+DURVlMPXOuSFACGmWqAoyk50HKwGOjLQgpySL/TcnQXClvFq8kNXGwyVzJsbwHpOHxI7oce69vaD6DaWFP75d3hx+PJeG9pauQCKzVP3skt3Hw/zDC7YfKcALD3aCwMmeNDwT3w0BUG6XZdG5lYhtFtTQYV7YuS3i/Jh3HShGbtm07JKOEFiPkxv2+XNaAX3gFEpbng6zamTanfyMXCJIiglAEqiyWHQ=", "visibilityTimeout": 2271 } ], "queueUrl": "https://sqs.ap-southeast-4.amazonaws.com/123456789012/MyQueue" }, "responseElements": { "successful": [ { "id": "0" } ] }, "requestID": "d49ab65f-9dc7-54b8-875c-eb9b4c42988b", "eventID": "ca16c8c2-c4ba-4eb5-a54c-e650a10266d4", "readOnly": false, "resources": [ { "accountId": "123456789012", "type": "AWS::SQS::Queue", "ARN": "arn:aws:sqs:ap-southeast-4:123456789012:MyQueue" } ], "eventType": "AwsApiCall", "managementEvent": false, "recipientAccountId": "123456789012", "eventCategory": "Data", "tlsDetails": { "tlsVersion": "TLSv1.2", "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256", "clientProvidedHostHeader": "sqs.ap-southeast-4.amazonaws.com" } }