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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠