AWS: Set step function timeout

0

I am new to AWS. We have a yaml file defined like below to run our step function.

I want to set a timeout for the step function in AWS parameter store and refer it in the file. I created a parameter from AWS console. But I am not sure how to refer it in the yaml file. After reading the documentation I understood that it is declared under "States" property as "Timeout".

xxxStateMachine:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      StateMachineName: !Sub ${AWS::StackName}-StateMachine
      RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/roleName
      DefinitionString:
        !Sub
        - |-
          {
          	"Comment": "Calls xxx state update job invoker lambda",
          	"StartAt": "xxxCheckJob",
          	"States": {
              "Timeout": ${},    // IS this where the timeout has to be defined?
              "xxxCheckJob": {
          			"Type": "Task",
          			"Resource": "${lambdaBDCArn}",
          			"ResultPath": "$.isBusinessDay",
          			"OutputPath": "$",
          			"Next": "xxxCheckJobStatus"
              },
              "businessDayCheckJobStatus": {
          			"Type": "Choice",
          			"Choices": [
                  {
                    "Variable": "$.x",
                    "BooleanEquals": true,
                    "Next": "xxxStatexxJob"
          			  },
                  {
                    "Not": {
                      "Variable": "$.isBuxxy",
                      "BooleanEquals": true
                    },
                    "Next": "SuccessState"
          			  }
                ]
          		},
          		"xxxStateUpdateJob": {
          			"Type": "Task",
          			"Resource": "${lambdaRSUArn}",
          			"ResultPath": "$.detail.requestParameters.invocationStatus",
          			"OutputPath": "$.detail.requestParameters",
          			"Next": "xxxStateUpdateJobStatus"
          		},
          		"xxxStateUpdateJobStatus": {
          			"Type": "Task",
          			"Resource": "${lambdaJSArn}",
          			"Parameters": {
          				"jobName.$": "$.invocationStatus.jobId"
          			},
          			"ResultPath": "$.jobStatus",
          			"OutputPath": "$",
          			"Next": "checkJobStatus"
          		},
          		"checkJobStatus": {
          			"Type": "Choice",
          			"Choices": [
                  {
                    "Variable": "$.jobStatus.status",
                    "StringEquals": "FAILED",
                    "Next": "FailState"
          			  },
                  {
                    "Variable": "$.jobStatus.status",
                    "StringEquals": "SUCCEEDED",
                    "Next": "SuccessState"
          			  },
                  {
                    "Not": {
                      "Variable": "$.jobStatus.status",
                      "StringEquals": "SUCCEEDED"
                    },
                    "Next": "Wait X Seconds"
          			  }
                ]
          		},
          		"Wait X Seconds": {
          			"Type": "Wait",
          			"Seconds": 20,
          			"Next": "xxxStateUpdateJobStatus"
          		},
          		"SuccessState": {
          			"Type": "Succeed"
          		},
          		"FailState": {
          			"Type": "Fail",
          			"Cause": "Invalid response.",
          			"Error": "ErrorA"
          		}
          	}
          }
        - {lambdaRSUArn: !GetAtt [ xx, Arn ],
           lambdaJSArn: !GetAtt [ xx, Arn ],
           lambdaBDCArn: !GetAtt [ xx, Arn ]}

I have the following questions:

  1. How to access timeout value in the yaml file. Is this the syntax - "Timeout": ${parameterName}

  2. How to configure the step function so that it exits if the timeout reaches and job status is in pending state.

  3. How to configure the step function so that it does not exits if the timeout reaches and the job status is in running state.

Can anyone help me configure these?

已提问 2 年前2847 查看次数
1 回答
0

Hi

Please review TimeoutSeconds documentation if it meets your need. If the task runs longer than the specified seconds, the state will fail with a States.Timeout error name. https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html https://docs.aws.amazon.com/step-functions/latest/dg/sfn-stuck-execution.html

There is a good tutorial showing the use: https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-creating-activity-state-machine.html

AWS
已回答 2 年前
  • Thanks for the reply. Was wondering if I can use this specific to the status of the machine. For eg I want it to timeout only if the step function is stuck in pending status

  • When we start the job ,it initially goes into pending state before going into running .We want to have a timeout for just the pending state and not running state

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则