Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

472
Visualizações
AWS Step Function: check for null

Step Function is defined like that:

{
  "StartAt": "Decision_Maker",
  "States": {
    "Decision_Maker":{
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.body.MyData",
          "StringEquals": "null", //that doesn't work :(
          "Next": "Run_Task1"
        }],
        "Default": "Run_Task2"
    },
    "Run_Task1": {
      "Type": "Task",
      "Resource": "url_1",
      "Next": "Run_Task2"
    },
    "Run_Task2": {
      "Type": "Task",
      "Resource": "url_2",
      "End": true
    }
  }
}

Basically it's a choice between 2 tasks. Input data is like this:

{
    "body": {
        "prop1": "value1",
        "myData": {
            "otherProp": "value"
        }
    }
}

The problem is that sometimes there's no myData in JSON. So input may come like this:

{
    "body": {
        "prop1": "value1",
        "myData": null
    }
}

How do I check whether or not myData is null?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

As of August 2020, Amazon States Language now has an isNull and isPresent Choice Rule. Using these you can natively check for null or the existence of a key in the state input inside a Choice state.

Example:

{ "Variable": "$.possiblyNullValue", "IsNull": true }

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html#amazon-states-language-choice-state-rules

over 4 years ago · Santiago Trujillo Relatório

0

The order matters. Set the "IsPresent": false first, then the "IsNull": true, finally the scalar comparison last.

    "Check MyValue": {
      "Comment": "Check MyValue",
      "Type": "Choice",
      "Default": "ContinueWithMyValue",
      "Choices": [
        {
          "Or": [
            {
              "Variable": "$.MyValue",
              "IsPresent": false
            },
            {
              "Variable": "$.MyValue",
              "IsNull": true
            },
            {
              "Variable": "$.MyValue",
              "BooleanEquals": false
            }
          ],
          "Next": "HaltProcessing"
        },
        {
          "Variable": "$.MyValue",
          "BooleanEquals": true,
          "Next": "ContinueWithMyValue"
        }
      ]
    },
over 4 years ago · Santiago Trujillo Relatório

0

As per my experience, Choice Type can't deal nulls. Best way could be pre-processing your input using a lambda in the very first state and return the event formatting it as "null". Below code snippet might help.

def lambda_handler(event, context):
if event['body']['MyData']:
    return event
else:
    event['body']['MyData']="null"
    return event

Note: This also handles empty string.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda