I am attempting to create an AWS StepFunctions workflow where I have a Lambda task followed by an ECS/Fargate task.
The Lambda takes an ID as an input and outputs some data in JSON form that is used by the ECS task, which is runs a Python script in its container environment. What I would like to do in StepFunctions is the following flow:
{ id: 1234 } -> [Lambda] -> { id: 1234, data: {...} }
{ id: 1234, data: {...} } -> [ECS] -> { id: 1234, result: "bar"}
For reference, here is an example configuration of an ECS Task: https://docs.aws.amazon.com/step-functions/latest/dg/sample-project-container-task-notification.html
I cannot figure out any way to pass the structured JSON input of a ECS Task to the container running the task.
Here are the things I have found so far:
- I can pass individual fields of a JSON input to the container by using JSONPath to select individual fields of the input and set them to environment variables. But if I assign the entire
inputobject ($) to an environment variable, then it fails at runtime with a serialization error ([Object] cannot be converted to a string). - I can create an intermediate lambda that takes the input and converts it to a JSON string that is stored in a single key-value in the
output, then assign this single string key-value to an environment variable of ECS Task and parse it. However, this requires adding an entire extra Task and a few seconds of runtime + cost.
Here are some things I can't do:
- There doesn't seem to be any mechanism in
boto3to get theinputof an existing ECS Task. I can get theinputof an unassigned Activity, or I can get the input of the entire Execution. But there is no API for just getting the input of an existing, running Task, even though I have a Task Token. - I cannot modify my original Lambda to output JSON as a string. I am using this result in multiple places (parallel tasks), and the other tasks are Lambdas that consume specific subfields of the
outputas theirinput.
What is the intended mechanism to pass a structured JSON object defined as the input to a Task to the executing container of an ECS/Fargate Task?