【问题标题】:Cloudwatch Event Rule doesn't invoke when source state machine fails源状态机失败时不调用 Cloudwatch 事件规则
【发布时间】:2020-09-17 22:09:12
【问题描述】:

我有一个运行 2 个独立 lambda 的步进函数。如果步进函数失败或超时,我想通过 SNS 收到一封电子邮件,告诉我步进函数失败。我使用 cloudformation 创建了事件规则,并在事件模式中指定了状态机 ARN。当 step 函数失败时,不会发送任何电子邮件。如果我删除 stateMachineArn 参数并运行我的 step 函数,我会收到失败电子邮件。我已经多次检查了我正在为状态机输入正确的 ARN。事件规则的 CF 如下(采用 YAML 格式)。谢谢。

  FailureEvent:
    Type: AWS::Events::Rule
    DependsOn:
      - StateMachine
    Properties:
      Name: !Ref FailureRuleName
      Description: "EventRule"
      EventPattern:
        detail-type:
          - "Step Functions Execution Status Change"
        detail:
          status:
            - "FAILED"
            - "TIMED_OUT"
        stateMachineArn: ["arn:aws:states:region:account#:stateMachine:statemachine"]
      Targets:
        -
          Arn:
            Ref: SNSARN
          Id: !Ref SNSTopic

【问题讨论】:

  • 请正确格式化您的代码,click here to learn how
  • 我在 SUCCEEDED 状态下遇到了同样的问题,您找到答案了吗?
  • 它对我有用,请确保您使用的是现有的 ARN!

标签: amazon-cloudwatch aws-step-functions


【解决方案1】:

我确实修复了这个问题并对其进行了扩展,以调用一个使用 lambda 发布自定义 SNS 电子邮件的 lambda。我的对齐在我的 EventPattern 部分中关闭。见下文。感谢@Marcin。

FailureEvent:
Type: AWS::Events::Rule
DependsOn:
  - FMIStateMachine
Properties:
  Description: !Ref FailureRuleDescription
  Name: !Ref FailureRuleName
  State: "ENABLED"
  RoleArn:
    'Fn::Join': ["", ['arn:aws:iam::', !Ref 'AWS::AccountId', ':role/', !Ref LambdaExecutionRole]]
  EventPattern:
    detail-type:
      - "Step Functions Execution Status Change"
    detail:
      status:
        - "FAILED"
        - "TIMED_OUT"
      stateMachineArn: [!Ref StateMachine]
  Targets:
    - Arn:
        'Fn::Join': ["", ['arn:aws:lambda:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':function:', !Ref FailureLambda]]
      Id: !Ref FailureLambda
      Input: !Sub '{"failed_service": "${StateMachineName}","sns_arn": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${SNSTopic}"}'

【讨论】:

    猜你喜欢
    • 2017-09-07
    • 2020-01-03
    • 2019-08-06
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2019-07-15
    相关资源
    最近更新 更多