user3640030
user3640030

Reputation: 191

AWS Step Function Map Input from Lambda returning a string array

I have a lambda integrated with API gateway (Proxy Integration)

Lambda returns :

    collection = [
       {
          "name": "string1"
       },
       {
          "name": "string2"
       } 
     ]

   response = {
        'statusCode': 200,
        'body': JSON.stringify(collection)
       }
    return response 

This works fine because in Proxy Integration body needs to be a string. If I dont convert the JSON array into string, API gateway throws 502 gateway error. So I need to convert it into string.

Now, Im planning to use same lambda for AWS Step function where a map needs JSON array as input.

How do I convert this stringify-ed JSON array to normal array for Map to process?

I have tried to use States.StringToJson

Old:

enter image description here

New:

enter image description here

I get invalid JSONPath format error.

Upvotes: 0

Views: 1374

Answers (2)

user3640030
user3640030

Reputation: 191

Along with Jason answer following documentation helped

https://states-language.net/spec.html#intrinsic-functions

Upvotes: 0

Jason Wadsworth
Jason Wadsworth

Reputation: 8885

You can use the States.StringToJson intrinsic function to convert the string to JSON.

Upvotes: 1

Related Questions