Krishna Chaitanya
Krishna Chaitanya

Reputation: 2663

AWS: Set step function timeout

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": "${lambdaDArn}",
                    "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": "${lambdaSArn}",
                    "ResultPath": "$.detail.requestParameters.invocationStatus",
                    "OutputPath": "$.detail.requestParameters",
                    "Next": "xxxStateUpdateJobStatus"
                },
                "xxxStateUpdateJobStatus": {
                    "Type": "Task",
                    "Resource": "${lambdaJrn}",
                    "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"
                }
            }
          }
        - {lambdaArn: !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?

Upvotes: 1

Views: 2652

Answers (1)

fedonev
fedonev

Reputation: 25739

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

A TimeoutSeconds integer value can be set for the overall State Machine execution and for a Task State. TimeoutSeconds cannot be interpolated dynamically at execution-time. It is a fixed part of the State Machine definition.

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

Task states have optional Retry and Catch configuration to handle errors, including States.Timeout errors. State Machine timeouts result in a failed execution.

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

See above.

Upvotes: 1

Related Questions