title | date |
---|---|
AWS Lambda |
2017-06-09 04:45:00 UTC |
Since the output data from a Lambda function is not static and varies with the function, a sample response is needed to generate an action's output schema, also known as output datatree. This datatree allows you to map the output from the function into another recipe step.
All you need to do is provide a sample response to the Response body
input field. Now the format of your response will determine what the sample output should look like. We will explore how to format a sample response for 2 cases: JSON response body and single primitive data.
There are 2 ways to configure this input field: Using a sample JSON or creating a schema definition. This article focuses on using sample JSON.
Clicking on generate from JSON sample
will open a pop up which looks like this:
Provide a valid JSON. More details about formatting a valid JSON body for the AWS lambda connector in the next section.
Workato requires all data be presented as key & value pairs. This is done so that we can map values using it's respective key. JSON data format is a good example. For the AWS lambda connector, we require all response JSON to be wrapped in a parent "response"
object. Hence using a given response like this:
{
"id": 123,
"name": "Ee Shan",
"email": "eeshan@workato.com"
}
Wrap it in a parent `"response" object:
{
"response": {
"id": 123,
"name": "Ee Shan",
"email": "eeshan@workato.com"
}
}
Insert the output JSON and click Generate
. This generates the following output datatree:
If the lambda function returns non-JSON data structure, like a single string, integer or a simple boolean value, it will likewise need to be wrapped in a parent "response"
object. Let's look at a simple function that returns an integer value (ID for example). A sample response will be:
4990
Wrap it in a parent "response"
object:
{
"response": 4990
}
Insert the output JSON and click Generate
. This generates the following output datatree: