Step Machine - is there any kind of intrinsic functions for if statements?

0

I'm pretty new to Step Machines, I've created a relatively complex machine - which works quite well and is hooked up to API gateway. There's one piece of it which just feels a bit ugly to me, I've created this example but let me be clear that this is a "fake" example so explaining better ways of doing it via the API or whatever doesn't help much, I just want to achieve what I'm showing below but ideally in a neater way. I should also add what I've done works, but just isn't pretty.

Basically I set a variable using the pass functions with two different outputs based on a choice, what it feels like I should be able to do is something LIKE;

"S.$": "States.If($.resolution>1000,'Desktop','Mobile')"

Enter image description here

{
  "Comment": "A description of my state machine",
  "StartAt": "Choice",
  "States": {
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.resolution",
          "NumericGreaterThan": 1000,
          "Next": "Status is OK"
        }
      ],
      "Default": "Status is Fail"
    },
    "Status is OK": {
      "Type": "Pass",
      "Next": "DynamoDB PutItem",
      "Result": {
        "type": "Desktop"
      },
      "ResultPath": "$.display"
    },
    "Status is Fail": {
      "Type": "Pass",
      "Next": "DynamoDB PutItem",
      "Result": {
        "type": "Mobile"
      },
      "ResultPath": "$.display"
    },
    "DynamoDB PutItem": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName": "MyDynamoDBTable",
        "Item": {
          "Name": {
            "S.$": "$.name"
          },
          "DisplayType": {
            "S.$": "$.display.type"
          }
        }
      },
      "End": true
    }
  }
}
질문됨 2년 전1333회 조회
2개 답변
0

This is the list of intrinsic functions. As you can see, it does not include an if function.

Your only option is to use a Choice state.

I will raise it to the service team.

profile pictureAWS
전문가
Uri
답변함 2년 전
0

Hello, currently there is no intrinsic function in Step Functions which can control the execution flow like Choice state. Choice state is the only viable option right now in this use case. Please refer to [1] for more information on Intrinsic Functions in Step Functions

[1] Intrinsic functions: https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-intrinsic-functions.html

profile pictureAWS
지원 엔지니어
Bharat
답변함 2년 전

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

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

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

관련 콘텐츠