Search code examples
amazon-web-servicesaws-lambdaaws-cloudformationserverless-frameworkaws-event-bridge

EventBridge rule not triggering Lambda despite having resource policy statement on lambda


I've got a serverless file which creates an eventbridge rule on the default event bus:

    StepFunctionErrorEvent:
      Type: AWS::Events::Rule
      Properties:
        Name: ${self:custom.resourcePrefix}-step-function-error-event-rule
        Description: Event bus rule coordinating what targets receive Step Function error events
        EventPattern:
          source:
            - "aws.states"
          "detail-type":
            - "Step Functions Execution Status Change"
          detail:
            state:
              - "FAILED"
              - "TIMED_OUT"
              - "ABORTED"
        Targets:
          - Arn: ${cf:${self:custom.resourcePrefix}-service-internal-slack-integration.PostSlackMessageLambdaArn}
            Id: "ErrorSlackMessage"
            DeadLetterConfig:
              Arn: !GetAtt DefaultErrorTargetDLQ.Arn
    DefaultErrorTargetDLQ:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: ${self:custom.resourcePrefix}-DefaultErrorTargetDL

And in a seperate serverless file which also gets deployed I'm adding the following Lambda permission to pl-us-east-2-pilot-post-slack-message:

resources:
  Resources:
    TriggerPostSlackMessageLambda:
      Type: AWS::Lambda::Permission
      Properties:
        FunctionName: !GetAtt PostSlackMessageLambdaFunction.Arn
        Action: lambda:InvokeFunction
        Principal: events.amazonaws.com
        SourceArn: !Sub arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/pl-us-east-2-pilot-step-function-error-event-rule

However despite pl-us-east-2-pilot-post-slack-message lambda having the above listed as a permission under 'Resource based policy' (in the Lambda console) the EventBridge rule does not trigger when there is a Lambda failure. It does trigger if I create a new rule using the AWS Console, but for whatever reason it's not able to successfully trigger using serverless/CloudFormation.

Every post I seem to read about this topic makes mention of the same thing - that is to have the permission set on your Lambda, but I've done that and it's still not working. Does anyone have any idea what could be the reason why it's not triggering?


Solution

  • hard one to spot, but since i was using step functions

              detail:
                state:
                  - "FAILED"
                  - "TIMED_OUT"
                  - "ABORTED"
    

    should be

              detail:
                status:
                  - "FAILED"
                  - "TIMED_OUT"
                  - "ABORTED"