文件上传到 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/