如何使用 AWS CLI 启用 S3 对象日志记录到 Cloud Trail?
How do you enable S3 Object Logging to Cloud Trail using AWS CLI?
可以使用以下指南将 S3 存储桶上的对象记录到 Cloud trail,但这是通过控制台进行的。
https://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-cloudtrail-events.html
我一直在尝试找出一种通过 cli 执行此操作的方法,因为我想为许多存储桶执行此操作,但运气不佳。我在我的帐户上设置了一个新的云跟踪,并希望将其映射到 s3 存储桶以进行对象日志记录。有这个的cli吗?
# This is to grant s3 log bucket access (no link to cloudtrail here)
aws s3api put-bucket-logging
您似乎需要使用 CloudTrail put_event_selectors()
命令:
DataResources
CloudTrail supports data event logging for Amazon S3 objects and AWS Lambda functions.
(dict): The Amazon S3 buckets or AWS Lambda functions that you specify in your event selectors for your trail to log data events.
在 documentation page 中搜索 object-level
。
免责声明:puji
在接受的答案中的评论有效。这是该答案与资源的扩展。
这是关于如何通过 AWS CLI 执行此操作的 AWS 文档
https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/put-event-selectors.html
您感兴趣的特定 CLI 命令是上述文档中的以下命令。原始文档列出了同一存储桶中的两个对象。我已经修改它以覆盖两个桶中的所有对象。
aws cloudtrail put-event-selectors --trail-name TrailName --event-selectors '[{"ReadWriteType": "All","IncludeManagementEvents": true,"DataResources": [{"Type":"AWS::S3::Object", "Values": ["arn:aws:s3:::mybucket1/","arn:aws:s3:::mybucket2/"]}]}]'
如果您想要涵盖您的 AWS 账户中的所有 S3 存储桶,您可以使用 arn:aws:s3:::
而不是像下面这样的存储桶列表。
aws cloudtrail put-event-selectors --trail-name TrailName2 --event-selectors '[{"ReadWriteType": "All","IncludeManagementEvents": true,"DataResources": [{"Type":"AWS::S3::Object", "Values": ["arn:aws:s3:::"]}]}]'
可以使用以下指南将 S3 存储桶上的对象记录到 Cloud trail,但这是通过控制台进行的。
https://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-cloudtrail-events.html
我一直在尝试找出一种通过 cli 执行此操作的方法,因为我想为许多存储桶执行此操作,但运气不佳。我在我的帐户上设置了一个新的云跟踪,并希望将其映射到 s3 存储桶以进行对象日志记录。有这个的cli吗?
# This is to grant s3 log bucket access (no link to cloudtrail here)
aws s3api put-bucket-logging
您似乎需要使用 CloudTrail put_event_selectors()
命令:
DataResources
CloudTrail supports data event logging for Amazon S3 objects and AWS Lambda functions.
(dict): The Amazon S3 buckets or AWS Lambda functions that you specify in your event selectors for your trail to log data events.
在 documentation page 中搜索 object-level
。
免责声明:puji
在接受的答案中的评论有效。这是该答案与资源的扩展。
这是关于如何通过 AWS CLI 执行此操作的 AWS 文档
https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/put-event-selectors.html
您感兴趣的特定 CLI 命令是上述文档中的以下命令。原始文档列出了同一存储桶中的两个对象。我已经修改它以覆盖两个桶中的所有对象。
aws cloudtrail put-event-selectors --trail-name TrailName --event-selectors '[{"ReadWriteType": "All","IncludeManagementEvents": true,"DataResources": [{"Type":"AWS::S3::Object", "Values": ["arn:aws:s3:::mybucket1/","arn:aws:s3:::mybucket2/"]}]}]'
如果您想要涵盖您的 AWS 账户中的所有 S3 存储桶,您可以使用 arn:aws:s3:::
而不是像下面这样的存储桶列表。
aws cloudtrail put-event-selectors --trail-name TrailName2 --event-selectors '[{"ReadWriteType": "All","IncludeManagementEvents": true,"DataResources": [{"Type":"AWS::S3::Object", "Values": ["arn:aws:s3:::"]}]}]'