【问题标题】:Serverless Framework and AWS Step Functions (AWS State Machine) triggered from a file uploaded to S3从上传到 S3 的文件触发的无服务器框架和 AWS Step Functions(AWS 状态机)
【发布时间】:2021-02-09 01:27:24
【问题描述】:

我正在尝试在文件上传到 S3 存储桶后启动 AWS 状态机(步进函数)。 存储桶已经存在,并且项目是使用无服务器框架创建的。

为此,我在 serverless.yml 中创建了这个函数

    functions:
    
      imagewasuploadedevent:
        handler: src/stepfunctions/imageWasUploadedEvent.handler
        events:
         - s3:
            bucket: !Ref AttachmentsBucket
            existing: true
        iamRoleStatements:
          - Effect: "Allow"
            Action:
              - "states:StartExecution"
            Resource:
              - "*"

当文件上传到已经存在的S3存储桶“AttachmentsBucket”时应该触发这个函数,我希望它启动状态机处理

现在 Step Function 定义如下

stepFunctions:
  stateMachines:
    ValidateImageStateMachine:
      definition:
        Comment: "This state function validates the images after users upload them to S3"
        StartAt: imagewasuploadedevent
        States:
          imageWasUploadedEvent:
            Type: Task
            Resource:
              Fn::GetAtt: [imagewasuploadedevent, Arn]
            End: true

插件部分正在使用“serverless-step-functions”插件

plugins:
  - serverless-python-requirements
  - serverless-iam-roles-per-function
  - serverless-step-functions

但是,堆栈的 CloudFormation 失败并出现以下错误

 An error occurred: 

ValidateImageStateMachineStepFunctionsStateMachine - Invalid State Machine 
Definition: 'MISSING_TRANSITION_TARGET: Missing 'Next' target: imagewasuploadedevent at /StartAt, MISSING_TRANSITION_TARGET: State "imageWasUploadedEvent" is not reachable. at /States/imageWasUploadedEvent' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: 39217fe8-9dcd-4386-8549-b995619d2db6; Proxy: null).


我怀疑这与我正在做的事情无关,而是我们只能使用此插件通过 API 网关功能和时间表以及云监视事件来启动状态机。

有人能指出我正确的方向吗?

谢谢

【问题讨论】:

  • 顺便说一句。有没有办法在没有 Lambda 函数的情况下触发它?当然使用 Serverless 和 step functions 插件
  • 从 S3 我猜触发 StepFunction 的方式是通过 CloudWtach 事件规则。这是解释here。我最终无法使用无服务器框架和步骤函数插件以这种方式做到这一点
  • 谢谢!是的,它很复杂,我不知道如何让它工作,我会使用 Lambda

标签: amazon-web-services amazon-s3 aws-lambda serverless-framework aws-step-functions


【解决方案1】:

我认为这与亚马逊状态语言的区分大小写有关。

尝试使用imageWasUploadedEvent 更新StartAt

stepFunctions:
  stateMachines:
    ValidateImageStateMachine:
      definition:
        Comment: "This state function validates the images after users upload them to S3"
        StartAt: imageWasUploadedEvent
        States:
          imageWasUploadedEvent:
            Type: Task
            Resource:
              Fn::GetAtt: [imagewasuploadedevent, Arn]
            End: true

【讨论】:

    猜你喜欢
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    • 2021-08-30
    • 1970-01-01
    • 2020-05-19
    相关资源
    最近更新 更多