I am creating a lambda that should be called when objects are created in a certain bucket. I only want it to be called for certain key prefixes. I have seen examples of setting this up using a NotificationConfiguration on the bucket when the bucket is being defined:
NotificationConfiguration:
LambdaConfigurations:
- Function: !Ref SomeLambdaArn
Event: "s3:ObjectCreated:*"
Filter:
S3Key:
Rules:
- Name: prefix
Value: zip
However I would rather not modify the bucket's CloudFormation definition. With SAM, lambda event triggers can be defined on the lambda:
Events:
BucketEvent1:
Type: S3
Properties:
Bucket: Ref: Bucket1
Events:
- 's3:ObjectCreated:*'
But is there a way to restrict it to trigger only for certain prefixes? Alternatively, is there a way to add a NotificationConfiguration to an existing bucket?