我们可以将事件桥触发器添加到step函数中,就像我们为aws lambda所做的那样,以便当我们将事件推送到总线时,step函数会触发

问题描述 投票:0回答:1

一旦具有匹配模式(源)的事件被推送到事件总线,我就尝试触发步骤函数。我们是否可以将事件桥触发器附加到步骤函数,就像我们对 lambda 所做的那样,以便当我们使用无服务器框架将事件推送到总线时触发步骤函数。我尝试将相同的 eventbridge 配置添加到 lambda 和 SF,lambda 正在触发,但步骤函数不会。

这是 lambda 函数的 yml 块

lambdaName:
  handler: handlers/lambdaName.handler
  events:
  - eventBridge:
     name: subscriber-handler
     eventBus: arn:aws:events:region:account:event-bus/trigger-stepfunction
     pattern:
        source:
          - 'test-SF-trigger'

这是 Step 函数的 yml 块:

stepFunctions:
  stateMachines:
    XyzStateMachine:
      name: xyz-state-machine-name
      id: xyz-state-machine-id
      events:
        - eventBridge:
           name: subscriber-handler
           eventBus: arn:aws:events:region:account:event-bus/trigger-stepfunction
           pattern:
              source:
                - 'test-SF-trigger'
      definition:
        Comment: "AWS Step Functions state machine to fetch data from DB day wise, write it to file and send to DL"
        StartAt: "state1"
        States:
          state1:
            Type: "Task"
            Resource: 
              Fn::GetAtt: [XYZ_lambda, Arn]
            Next: 'state2' .........

对于上述情况,当我将具有匹配源的事件推送到偶数总线时,我能够触发 lambda,但无法触发步进函数。我们也可以这样做来触发stepfunction吗?如果可以,请让我知道我缺少什么?

Edit1:另外,如果我们不能为 SF 附加这样的自定义事件,请告诉我?

注意:我可以通过创建 cloudformation 总线和规则并在该规则的目标中配置步骤函数来触发 SF。请告诉我我们是否可以设置 AWS Step Functions 以对通过 EventBridge 传入的事件做出反应,如上面所示。

aws-lambda aws-cloudformation serverless-framework aws-step-functions aws-serverless
1个回答
0
投票

是的。不需要中间 lambda。看起来您的示例与状态机插件文档中的结构不同。

https://www.serverless.com/plugins/serverless-step-functions

另外,请确保您的总线/规则/sfn 的 iam 权限配置正确

stepFunctions:
  stateMachines:
    exampleCloudwatchEventStartsMachine:
      events:
        - cloudwatchEvent:
            eventBusName: 'my-custom-event-bus'
            event:
              source:
                - "my.custom.source"
              detail-type:
                - "My Event Type"
              detail:
                state:
                  - pending
      definition:
        ...
© www.soinside.com 2019 - 2024. All rights reserved.