amazon-web-services - 无服务器框架和 AWS Step Functions(AWS 状态机)由上传到 S3 的文件触发

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

文件上传到 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 网关功能和时间表以及云监视事件来启动状态机。

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

谢谢

最佳答案

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

尝试使用 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

关于amazon-web-services - 无服务器框架和 AWS Step Functions(AWS 状态机)由上传到 S3 的文件触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64543066/

相关文章:

node.js - 使用 Node fs 从 aws s3 存储桶读取文件

java - s3 hadoop错误:NoSuchMethodError:org.apache.hadoop.metrics2.lib.MetricsRegistry.newCounter

amazon-web-services - 在 CloudFormation 中创建 AWS WorkMail Lambda 调用权限

python - 如何在 S3 上存储大型 Python 依赖项(适用于无服务器的 AWS Lambda)

amazon-web-services - 如何在 CloudFormation 中使用 OR 实现多个条件?

amazon-web-services - AWS Amplify (AppSync + Cognito) 授权使用每个组织/租户的动态组

amazon-web-services - 向数百万个 S3 对象添加元数据

amazon-web-services - 如何一次从CloudFormation中删除多个全局二级索引?

amazon-web-services - 使用 CloudFormation 为 APIGateway 提供适当的子域

ruby-on-rails - rails 4 回形针上传到亚马逊 s3 不起作用