Search code examples
amazon-web-servicesamazon-s3boto3amazon-cloudtrail

How Do I Enable Object-Level Logging for an S3 Bucket using boto3


I'm trying to create an amazon cloudWatch rule which triggers whenever an object is uploaded into a bucket. I know that to do this I need to trigger on the PutObject Event, however best I can tell that requires enabling object level logging on the bucket. I will be using a multitude of buckets and want to be able to automate that process, and because of how most of the system is set up using boto3 seems to make the most sense. So how can I turn object-level logging on using boto3?

The only AWS official resource I've been able to find so far is: How Do I Enable Object-Level Logging for an S3 Bucket with AWS CloudTrail Data Events?

Which explains how to enable object level logging through the GUI. I've also looked through the boto3 library documentation

Both have ultimately not been helpful based on my understanding.

My chief goal is to enable object-level logging through boto3, if that's something that can be done.


Solution

  • You can configure an Amazon S3 Event so that, when a new object is created, it can:

    • Trigger an AWS Lambda function
    • Put a message in an Amazon SQS queue
    • Send a message to an Amazon SNS topic

    See: Configuring Amazon S3 Event Notifications