Amazon web services AWS Step功能-在条件下停止状态机执行
我附上了我的状态机的外观,并分享了它的定义以供参考。Amazon web services AWS Step功能-在条件下停止状态机执行,amazon-web-services,aws-step-functions,Amazon Web Services,Aws Step Functions,我附上了我的状态机的外观,并分享了它的定义以供参考。 服务状态重试等待状态在调用服务状态重试状态之前等待60秒,该状态调用lambda检查服务是否在服务创建?状态下创建 { "Comment": "Step Function for Deployment", "StartAt": "Start", "States": { "Start": { &
服务状态重试等待
状态在调用服务状态重试
状态之前等待60秒,该状态调用lambda检查服务是否在服务创建?
状态下创建
{
"Comment": "Step Function for Deployment",
"StartAt": "Start",
"States": {
"Start": {
"Type": "Pass",
"Next": "Service Status"
},
"Service Status": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Service Status Check",
"States": {
"Service Status Check": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-west-2:<acc-id>:function:<fn-name>",
"Payload": {
"stepFunctionState.$": "$$.State.Name",
"requestContext": {
"stepFunction": true,
"accountId": "<acc-id>"
},
"resource.$": "States.Format('{}/srvc', $$.Execution.Input.resource)",
"path.$": "States.Format('{}/srvc', $$.Execution.Input.path)",
"httpMethod": "POST",
"pathParameters.$": "$$.Execution.Input.pathParameters",
"body.$": "$$.Execution.Input.body",
"isBase64Encoded": false,
"headers": {},
"queryStringParameters": null
}
},
"ResultPath": "$.taskresult",
"Next": "Service Created?"
},
"Service Created?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.taskresult.Payload.body",
"StringMatches": "*\"isCreated\": \"false\"*",
"Next": "Service Status Retry Wait"
},
{
"Variable": "$.taskresult.Payload.body",
"StringMatches": "*\"isCreated\": \"true\"*",
"Next": "Service Status Check End"
}
],
"Default": "Service Status Retry Wait"
},
"Service Status Retry Wait": {
"Type": "Wait",
"Seconds": 60,
"Next": "Service Status Retry"
},
"Service Status Retry": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-west-2:<acc-id>:function:<func-name>",
"Payload": {
"stepFunctionState.$": "$$.State.Name",
"requestContext": {
"stepFunction": true,
"accountId": "<acc-id>"
},
"resource.$": "States.Format('{}/srvc', $$.Execution.Input.resource)",
"path.$": "States.Format('{}/srvc', $$.Execution.Input.path)",
"httpMethod": "POST",
"pathParameters.$": "$$.Execution.Input.pathParameters",
"body.$": "$$.Execution.Input.body",
"isBase64Encoded": false,
"headers": {},
"queryStringParameters": null
}
},
"ResultPath": "$.taskresult",
"Next": "Service Created?"
},
"Service Status Check End": {
"Type": "Pass",
"End": true
}
}
}
],
"Next": "End"
},
"End": {
"Type": "Pass",
"End": true
}
}
}
{
“注释”:“部署的步骤功能”,
“开始”:“开始”,
“国家”:{
“开始”:{
“类型”:“通过”,
“下一步”:“服务状态”
},
“服务状态”:{
“类型”:“并行”,
“分支机构”:[
{
“StartAt”:“服务状态检查”,
“国家”:{
“服务状态检查”:{
“类型”:“任务”,
“资源”:“arn:aws:states:::lambda:invoke”,
“参数”:{
“FunctionName”:“arn:aws:lambda:us-west-2:您有两个选项:
通过保留重试次数并在您选择的状态下进行检查,自行处理重试:
使用内置错误/重试。为此,请检查是否创建了服务,并抛出错误并将其包装为并行状态,重试次数为5:
{
“注释”:“部署的步骤功能”,
“开始”:“开始”,
“国家”:{
“开始”:{
“类型”:“通过”,
“下一步”:“服务状态”
},
“服务状态”:{
“类型”:“并行”,
“分支机构”:[
{
“StartAt”:“服务状态检查”,
“国家”:{
“服务状态检查”:{
“类型”:“任务”,
“资源”:“arn:aws:states:::lambda:invoke”,
“参数”:{
“函数名”:”arn:aws:lambda:us-west-2:似乎您可以使用内置在Step函数中的错误/重试功能,而不是重新创建自己的逻辑。它解释了在错误后重试。但是,在我的情况下,我不希望出现错误。我需要在重试状态执行5次后停止。我要说的是,您可以配置您的代码如果服务尚未启动,hat将检查服务状态以抛出错误。然后,您将能够利用Step函数提供的内置重试处理功能。
{
"Comment": "Step Function for Deployment",
"StartAt": "Start",
"States": {
"Start": {
"Type": "Pass",
"Next": "Service Status"
},
"Service Status": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Service Status Check",
"States": {
"Service Status Check": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-west-2:<acc-id>:function:<fn-name>",
"Payload": {
"stepFunctionState.$": "$$.State.Name",
"requestContext": {
"stepFunction": true,
"accountId": "<acc-id>"
},
"resource.$": "States.Format('{}/srvc', $$.Execution.Input.resource)",
"path.$": "States.Format('{}/srvc', $$.Execution.Input.path)",
"httpMethod": "POST",
"pathParameters.$": "$$.Execution.Input.pathParameters",
"body.$": "$$.Execution.Input.body",
"isBase64Encoded": false,
"headers": {},
"queryStringParameters": null
}
},
"ResultPath": "$.taskresult",
"Next": "Service Created?"
},
"Service Created?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.taskresult.Payload.body",
"StringMatches": "*\"isCreated\": \"false\"*",
"Next": "Throw Error"
},
{
"Variable": "$.taskresult.Payload.body",
"StringMatches": "*\"isCreated\": \"true\"*",
"Next": "Succeed"
}
],
"Default": "Throw Error"
},
"Throw Error": {
"Type": "Fail"
},
"Succeed": {
"Type": "Pass",
"End": true
}
}
}
],
"Next": "End",
"Retry": [
{
"ErrorEquals": [
"States.ALL"
],
"IntervalSeconds": 3,
"MaxAttempts": 5,
"BackoffRate": 1.5
}
]
},
"End": {
"Type": "Pass",
"End": true
}
}
}