I am trying to create an event rule that is triggered by a change in a file in S3 bucket in different AWS account. Detail description is here
So far the rule works fine with exact file names, but I need to make it work with filename prefixes. In the working example, the file name is an exact string in the non-working example the file name is a wildcard. Does CloudWatch Events Rule JSON pattern supports wildcards?
Working configuration:
{
"source": ["aws.s3"],
"account": ["1111111xxxxx"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject"],
"requestParameters": { "bucketName": ["mybucket"], "key": ["myfile-20180301.csv"] }
}
}
Non-working configuration:
{
"source": ["aws.s3"],
"account": ["1111111xxxxx"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject"],
"requestParameters": { "bucketName": ["mybucket"], "key": ["myfile-*"] }
}
}
There are several ways that you can use CloudWatch with Amazon S3. Monitor bucket storage using CloudWatch, which collects and processes storage data from Amazon S3 into readable, daily metrics. These storage metrics for Amazon S3 are reported once per day and are provided to all customers at no additional cost.
You can restrict access even if the users are granted access in an IAM policy. Using Amazon S3 Block Public Access as a centralized way to limit public access. Block Public Access settings override bucket policies and object permissions.
Amazon S3 uses this bucket key to create unique data keys for objects in a bucket, avoiding the need for additional KMS requests to complete encryption operations, and this translates to reduction of request traffic from Amazon S3 to KMS, allowing you to access encrypted objects within your S3 buckets at a fraction of ...
I found a fancy solution for this using Content-based filtering (released in February 2020) like prefix for example.
So in your case, the solution should be:
{
"source": ["aws.s3"],
"account": ["1111111xxxxx"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject"],
"requestParameters": {
"bucketName": ["mybucket"],
"key": [{ "prefix": "myfile-" }]
}
}
}
The template code gave by Marto was not working for me, however the doc led to a solution:
{
"source": ["aws.s3"],
"account": ["1111111xxxxx"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject"],
"requestParameters": {
"bucketName": ["mybucket"],
"key": [{"prefix": "myfile-*"}]
}
}
}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With