A developer is troubleshooting an AWS Step Functions state machine that invokes a Lambda function. The state machine consistently fails at the Lambda invocation step with a 'Lambda.Unknown' error. The Lambda function itself, when invoked directly, executes successfully without any errors and returns the expected output. The Step Functions execution role has the necessary 'lambda:InvokeFunction' permission. What is the MOST likely cause of the 'Lambda.Unknown' error in Step Functions?
- AThe Step Functions state machine's definition has an incorrect ARN or name for the Lambda function.
- BThe Lambda function is returning an invalid JSON response that Step Functions cannot parse.
- CThe Lambda function is experiencing cold starts, causing a timeout that Step Functions interprets as 'Unknown'.
- DThe Lambda function's execution role is missing permissions to interact with other AWS services it depends on.
Show answer & explanationAnswer & explanation
Correct answer: B. The Lambda function is returning an invalid JSON response that Step Functions cannot parse.
A 'Lambda.Unknown' error from Step Functions, specifically when the Lambda function runs successfully on direct invocation, often indicates that Step Functions received a response from Lambda that it could not parse as valid JSON. Step Functions requires Lambda functions to return valid JSON, even if it's an empty JSON object. If the Lambda returns plain text, XML, or malformed JSON, Step Functions will throw a 'Lambda.Unknown' error.
Why the other options are wrong
- A. An incorrect ARN would typically result in a 'Lambda.ResourceNotFoundException' or similar, not 'Lambda.Unknown'.
- C. Lambda cold starts would increase duration and potentially cause a timeout, but Step Functions would typically report a 'Lambda.Timeout' or 'States.Timeout' error, not 'Lambda.Unknown', if that were the case.
- D. If the Lambda's own role was missing permissions, it would fail even on direct invocation, which contradicts the problem statement.
Step Functions Lambda.Unknown Error
The 'Lambda.Unknown' error in AWS Step Functions, particularly when the Lambda function executes successfully on its own, frequently indicates that the Lambda function returned a response that Step Functions could not parse as valid JSON. Step Functions expects all Lambda outputs to be valid JSON.
- Occurs when Lambda output is not valid JSON.
- Lambda may execute successfully but return unexpected format.
- Step Functions cannot parse non-JSON, plain text, or malformed JSON.
Memory trick: Step Functions gets 'Confused' by 'Unknown' Lambda errors when the 'Output' isn't clean JSON.