'Global variable alternative in a AWS Step Function execution

Im running a workflow using a step function (with SAM), when I needed to send information between lambdas I've used events and everything was perfect! But now, I need that almost every lambda in my workflow have access to a constant received in the invocation input of the step function (it changes on every execution) like a global variable.

I know that I can solve it by returning it in every lambda output but I think that it is a very ugly solution :(

Is there any way to access the context of the execution and add data to it from a lambda in the step function ? Any other solution would be cool too.



Solution 1:[1]

Yes, see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html#input-output-resultpath-append

You can keep the input of the state machine execution and combine it with the result of the state.

Solution 2:[2]

Going through the docs, I see that you can access the context object from each state in the state machine.

You can pass the information that you need to be global as the input to your state machine and then, access the state machine input from the context object.

You can refer the linked doc to see how to access the context object.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Milan Gatyas
Solution 2 alimaqsood