Skip to content

helper lambda function for json to json transforms, useful to derive parameters in aws step functions implemented with serverless framework

Notifications You must be signed in to change notification settings

rudygt/sf-json-helper

Repository files navigation

sf-json-helper

helper lambda function for json to json transforms, useful to derive parameters in aws step function states

this lambda uses the python jsonpath-ng library to allow arbitrary json to json transforms from the input event and the lambda output.

sample result

Running Locally

Docker is required to deploy (dockerized pip to build the package by https://www.npmjs.com/package/serverless-python-requirements?activeTab=readme)

npm install

pip install -r requirements.txt

./localInvoke.sh

Examples

derive a property using a simple string concatenation. any properties in the input data prefixed with "expression_" will be evaluated as jsonpath expressions and the piece after the underscore will be used as the new property name, so in this case the "expression_d" part will create a new property on the output with name "d" and the value for that property will be computed using the jsonpath expression provided, in this case '$.k + " constant string"'.

Input

{
	"k": "v",
	"expression_d": "$.k + \" constant string\""	
}

Output

{
	"d": "v constant string"	
}

Enable input forwarding

if the property "_forward" is present in the input event, all non expression keys will be appended to the output object*

Input

{
	"_forward" : true,
	"k": "v",
	"expression_d": "$.k + \" constant string\""
}

Output

{
	"d": "v constant string",
	"k": "v"
}

Json unwrapping

when calling a step function from another step function, the json output of the state machine will be returned as a json string, this feature could be used to convert the json string to a property in the output object. In a similar way to the expression handling, using the "unescape_" prefix to instruct the lambda what to do, anything after the underscore will be used as the resulting property name for the parsed data passed input.

Input

{
	"unescape_data": "{ \"key\" : \"value\" }"
}

Output

{
	"data": {
		"key": "value"
	}
}

About

helper lambda function for json to json transforms, useful to derive parameters in aws step functions implemented with serverless framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published