amazon-web-servicesaws-lambdaaws-event-bridge

AWS Cloudformation Lambda and Event Rule - Lambda not getting triggered with s3 event with a suffix?


I have created a lambda and s3 event rule using cloudformation but lambda is not getting triggered as per configured rule. As per event rule I want lambda to trigger whenever a file is created in a specific s3 bucket with a specific suffix. Rule is given permission to invoke lambda. But when I upload a file (e.g. portfolio.testSuffix) lambda is not getting triggered.

  EventRule:
    Type: AWS::Events::Rule
    Properties:
      Description: 'test s3 event'
      EventPattern:
        source:
          - 'aws.s3'
        detail:
          eventSource:
            - 's3.amazonaws.com'
          eventName:
            - 'CopyObject'
            - 'PutObject'
          requestParameters:
            bucketName:
              - 'test-bucket'
            key:
              - |
               {"suffix": ".testsuffix"}
      State: 'ENABLED'
      Targets:
        -
          Arn: !GetAtt TestLambda.Arn
          Id: 'TestLambdaTargetId'
  LambdaInvokePermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: 'lambda:InvokeFunction'
      FunctionName: !GetAtt TestLambda.Arn
      Principal: 'events.amazonaws.com'
      SourceArn: !GetAtt EventRule.Arn        
          

Can anyone help to identify what is wrong in this configuration and why lambda is not getting triggered ?


Solution

  • As @Aris answers highlights, EventBridge does support suffix matching as well, as stated in the documentation.


    Old answer from 2021

    According to the Eventbridge documentation the suffix pattern is not supported.

    key:
     - |
      {"suffix": ".testsuffix"}
    

    Here's a list of all the comparison operators available in EventBridge:

    Null, Empty, Equals, And, Or, Not, Numeric (equals), Numeric (range), Exists, Does not exist, Begins with

    See Content-based filtering as well