我正在查看我的serverless.yml
上的实现是否错误。据我所知,我的Retry:
逻辑已被忽略。
状态机在第二个功能(callTextract
,CallTextract
状态)上失败,并且状态机在失败时立即再次执行。
由于调用Textract的次数过多而导致另一个错误,从而导致另一个失败,并且循环每秒持续数十次。阻止疯狂的唯一方法是运行sls remove
。
这是我的serverless.yml
:
service: textract-service
provider:
name: aws
runtime: python3.7
timeout: 10
region: us-east-1
cfLogs: true
environment:
STATE_MACHINE_ARN: ${self:resources.Outputs.TextractStepFunctions.Value}
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:PutObject"
- "states:*"
Resource:
Fn::Join:
- ""
- - "the-chumiest-bucketARN or *"
- ${self:resources.Outputs.TextractStepFunctions.Value}
plugins:
- serverless-plugin-existing-s3
- serverless-step-functions
- serverless-pseudo-parameters
- serverless-plugin-existing-s3
layers:
boto3Layer:
package:
artifact: boto3_layer.zip
allowedAccounts:
- "*"
functions:
startTextractStateMachine:
handler: src/start_textract_state_machine.lambda_handler
role: roleArn
layers:
- {Ref: Boto3LayerLambdaLayer}
events:
- existingS3:
bucket: the-chumiest-bucket
events:
- s3:ObjectCreated:*
rules:
- prefix: clients/client1/input/
- suffix: .pdf
callTextract:
handler: src/call_textract.lambda_handler
role: roleArn
layers:
- {Ref: Boto3LayerLambdaLayer}
getTextractOutput:
handler: src/get_textract_output.lambda_handler
role: roleArn
layers:
- {Ref: Boto3LayerLambdaLayer}
parseTextractOutput:
handler: src/parse_textract_output.lambda_handler
role: roleArn
layers:
- {Ref: Boto3LayerLambdaLayer}
stepFunctions:
stateMachines:
textractStepFunc:
name: TextractStepFunctions
definition:
Comment: A state machine for the Textract OCR process.
StartAt: StartTextractStateMachine
States:
StartTextractStateMachine:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:#{AWS::StackName}-startTextractStateMachine"
Next: CallTextract
Retry:
- ErrorEquals:
- States.ALL
IntervalSeconds: 1
MaxAttempts: 1
BackoffRate: 2
CallTextract:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:#{AWS::StackName}-callTextract"
Next: GetTextractOutput
Retry:
- ErrorEquals:
- States.ALL
IntervalSeconds: 1
MaxAttempts: 1
BackoffRate: 2
GetTextractOutput:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:#{AWS::StackName}-getTextractOutput"
Next: ParseTextractOutput
Retry:
- ErrorEquals:
- States.ALL
IntervalSeconds: 1
MaxAttempts: 1
BackoffRate: 2
ParseTextractOutput:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:#{AWS::StackName}-parseTextractOutput"
Retry:
- ErrorEquals:
- States.ALL
IntervalSeconds: 1
MaxAttempts: 1
BackoffRate: 2
End: true
resources:
Outputs:
TextractStepFunctions:
Description: The ARN of the state machine
Value:
Ref: TextractStepFunctions
我以前已经使用GUI控制台在Step Functions机器上实现了相同的代码,没有任何问题,因此问题必须在无服务器实现内。