CodexBloom - Programming Q&A Platform

AWS Step Functions Failing to Pass Dynamic Parameters to Lambda Function in Node.js

👀 Views: 4 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-05
aws lambda step-functions JavaScript

I'm working on a personal project and I've searched everywhere and can't find a clear answer. I'm using AWS Step Functions to orchestrate a workflow that includes a Lambda function written in Node.js (v14.x)... I need to pass dynamic parameters to the Lambda function based on the output of a previous state, but I'm encountering issues with the resulting payload not being formatted as expected. In my Step Function definition, I'm trying to pass parameters like this: ```json { "Comment": "A Hello World example of the Amazon States Language.", "StartAt": "ProcessData", "States": { "ProcessData": { "Type": "Task", "Resource": "arn:aws:lambda:us-west-2:123456789012:function:MyFunction", "Parameters": { "input.$": "$.previousState.output", "additionalParam": "SomeValue" }, "End": true } } } ``` However, when I run the Step Function, the Lambda function receives the parameters incorrectly structured. The payload it receives looks like this: ```json { "input": null, "additionalParam": "SomeValue" } ``` It seems that the `input.$` path is not resolving to the expected output from the previous state. To troubleshoot, I've checked the execution history in the Step Functions console, and I can see that `$.previousState.output` is indeed returning the expected value when I check the output. I've tried modifying the `Parameters` section in various ways, including using different JSON path expressions, but nothing seems to work. I've also checked the IAM permissions, and the Lambda function has the necessary permissions to be invoked from Step Functions. Here is the relevant part of my Lambda function code that is supposed to log the received input: ```javascript exports.handler = async (event) => { console.log('Received event:', JSON.stringify(event, null, 2)); // Further processing... }; ``` I also attempted to simplify the `Parameters` to just pass static values for testing, and that worked fine, so the issue seems specific to using dynamic references. Could this be a limitation of Step Functions, or am I missing something in how to format my parameters? Any advice on how to properly pass dynamic output from one state to another would be greatly appreciated. This is part of a larger API I'm building. What's the best practice here? For context: I'm using Javascript on Linux. What's the best practice here? For context: I'm using Javascript on macOS. Any ideas how to fix this?