aws-stepfunctions-tasks: Unable to use `LambdaInvoke` task as `ItemProcessor` when using JSONata
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When a **`Map.jsonata()`** state uses **`itemProcessor()`** with a **`tasks.LambdaInvoke`** inside it, the CDK (tested with v2.134.0) synthesises **invalid ASL**.
At the map level it emits
```json
"ProcessorConfig": { "Mode": "ITEM_PROCESSOR", "QueryLanguage": "JSONata" }
```
but the generated `LambdaInvoke` child state still contains a **`Parameters`** block.
The Step Functions schema forbids mixing those two worlds: the *JSONPath*‑style fields (`InputPath`, `Parameters`, `ResultSelector`, …) are **not allowed** in a state (or workflow) whose `QueryLanguage` is `JSONata` .
As a result the service rejects the template with
```
SCHEMA_VALIDATION_FAILED: The QueryLanguage is set to 'JSONata',
but field 'Parameters' is only supported for the 'JSONPath' QueryLanguage …
```
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
CDK should produce ASL that passes Step Functions validation.
Either
* remove the `Parameters` field and emit `Arguments`/`Output` (JSONata‑style), or
* fall back to `QueryLanguage: JSONPath` for the `LambdaInvoke` state (which is afaik not possible if `queryLanguage` has been set on the whole step function).
Deployment should succeed and the state machine should execute.
### Current Behavior
`cdk deploy` (or CloudFormation update) fails with **`UPDATE_FAILED`** on the `AWS::StepFunctions::StateMachine` resource. The error is exactly the one quoted above, and the stack rolls back.
### Reproduction Steps
The snippet below can be copied into a fresh CDK v2 TypeScript app and deployed; nothing except `aws-cdk-lib` and `constructs` is required.
```ts
// file: lib/bug-stack.ts
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
export class BugStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// dummy Lambda – returns its input
const fn = new lambda.Function(this, 'Fn', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = e => e;'),
});
// 1) MAP in ITEM_PROCESSOR mode + JSONata
const map = sfn.Map.jsonata(this, 'Map', {
items: sfn.ProvideItems.jsonata('{% [ { "foo": "bar" } ] %}'),
});
// 2) little Pass to prove Pass works fine
const pass = new sfn.Pass.jsonata(this, 'Pass', {
outputs: '{% $states.input %}',
});
// 3) LambdaInvoke – this is the problematic state
const invoke = new tasks.LambdaInvoke(this, 'Invoke', {
lambdaFunction: fn,
payload: sfn.TaskInput.fromObject({
foo: '{% $states.input.foo %}',
}),
});
// assemble the iterator
map.itemProcessor(pass.next(invoke));
// top‑level state‑machine, JSONata turned on
new sfn.StateMachine(this, 'StateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(map),
queryLanguage: sfn.QueryLanguage.JSONATA,
});
}
}
```
**How to run**
```bash
# 1. create a new project
npx cdk@2 init app --language typescript
npm i aws-cdk-lib constructs
# 2. replace lib/-stack.ts with the file above
npm run build
cdk deploy # fails with SCHEMA_VALIDATION_FAILED
```
**What you should see**
```
Invalid State Machine Definition:
SCHEMA_VALIDATION_FAILED: The QueryLanguage is set to 'JSONata',
but field 'Parameters' is only supported for the 'JSONPath' QueryLanguage
at /States/Map/ItemProcessor/States/Invoke/Resource
```
---
*Removing the `LambdaInvoke` or removing `queryLanguage` from the `StateMachine` and setting it per state (and using `Map.jsonPath`) makes the deployment succeed, which confirms the issue is confined to `LambdaInvoke` inside an `itemProcessor` in JSONata mode.*
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.1013.0
### Framework Version
_No response_
### Node.js Version
v22.14.0
### OS
macOS 15.4.1
### Language
TypeScript
### Language Version
TypeScript 5.6.3
### Other information
_No response_
Contributor guide
Research direction
Start with the reproduction in lib/bug-stack.ts, run npm run build and synthesize or deploy it to inspect the generated ASL at /States/Map/ItemProcessor/States/Invoke/Resource. Trace the LambdaInvoke and itemProcessor entry points, then verify that the generated state machine passes Step Functions validation and deployment succeeds without the JSONPath-only Parameters field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100