Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

471
Views
Función de paso de AWS: verificar nulo

La función de paso se define así:

 { "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 } } }

Básicamente es una elección entre 2 tareas. Los datos de entrada son así:

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

El problema es que a veces no hay myData en JSON. Así que la entrada puede venir así:

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

¿Cómo verifico si myData es nulo o no?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

A partir de agosto de 2020, Amazon States Language ahora tiene una regla de elección isNull y isPresent . Con estos, puede verificar de forma nativa si hay un null o la existencia de una clave en la entrada de estado dentro de un estado Choice.

Ejemplo:

 { "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 Report

0

El orden importa. Establezca " IsPresent": false primero, luego "IsNull": true , finalmente la comparación escalar al final.

 "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 Report

0

Según mi experiencia, Choice Type no puede lidiar con valores nulos. La mejor manera podría ser preprocesar su entrada usando un lambda en el primer estado y devolver el evento formateándolo como "nulo". El siguiente fragmento de código podría ayudar.

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

Nota: Esto también maneja cadenas vacías.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!