I’m trying to trigger a Lambda when a new file is uploaded to an S3 bucket. We’re configuring the bucket in CloudFormation using the NotificationConfiguration > LambdaConfigurations > ObjectCreated > s3:ObjectCreated:* with a filter on the suffix. We want the lambda to be triggered whenever a png file is added to the bucket. We want this to happen for any casing of filename suffix e.g. .png or .PNG. Here is the CF
"NotificationConfiguration": {
"LambdaConfigurations": [
{
"Event": "s3:ObjectCreated:*",
"Filter": {
"S3Key": {
"Rules": [
{
"Name": "suffix",
"Value": "PNG"
}
]
}
}
The above ONLY works and triggers the Lambda for files with an uppercase suffix of "PNG", the lambda is not triggered for files with a suffix of "png".
How is it possible to make a suffix filter or filters or alternative approach that will trigger the Lambda regardless of suffix casing?
There’s relevant info here but it didn’t seem to solve this particular issue and it seems like a problem that would be encountered fairly often – https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-how-to-filtering.html
Thanks,
Sam
2
Answers
Amazon S3 file names (and the rules on the event notifications) are always case sensitive.
If you can’t change your implementation, you need an intermediate Lambda Function that process every S3 Event Notification, filter it manually in a case-insensitive way, and then call the right function in the chain.
I was able to create an S3 bucket NotificationConfiguration that triggers an existing Lambda function when objects with suffix
png
or with suffixPNG
are dropped into the S3 bucket.Here’s the YAML template (you can convert to JSON easily):