Correct method to add suffix for S3 notification

0

Hi, I am not sure what I am doing wrong but the code below don't seem to be working. I am adding multiple suffix to the notification so that only file with these extensions trigger the Lambda function but when I am adding the file with .wav, the lambda doesn't trigger. If I remove the suffix and then upload the file, the lambda activates.

someBucket.addEventNotification(
      s3.EventType.OBJECT_CREATED_PUT,
      new s3n.LambdaDestination(functionLambda), 
      {suffix: '.wav, .mp3, .mp4,'}
    );
asked 10 months ago799 views
1 Answer
1
Accepted Answer

It's because you can have only one sufix per event notification rule.

By doing this {suffix: '.wav, .mp3, .mp4,'} you are basically saying that you want to notify only objects that terminate with '.wav, .mp3, .mp4,' as a single suffix e.g. "myobject.wav, .mp3, .mp4," which is impossible.

To achieve what you want you will need to create 3 different event notification rules, one for each suffix:

audioTextBucket.addEventNotification(
      s3.EventType.OBJECT_CREATED_PUT,
      new s3n.LambdaDestination(functionLambda), 
      {suffix: '.wav'}
    );
audioTextBucket.addEventNotification(
      s3.EventType.OBJECT_CREATED_PUT,
      new s3n.LambdaDestination(functionLambda), 
      {suffix: '.mp3'}
    );
audioTextBucket.addEventNotification(
      s3.EventType.OBJECT_CREATED_PUT,
      new s3n.LambdaDestination(functionLambda), 
      {suffix: '.mp4'}
    );

Hope this answers your question, let me know if I can still help somehow.

answered 10 months ago
profile pictureAWS
EXPERT
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions