aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(stepfunctions-tasks): EmrCreateCluster rejects JsonPath values for ebsRootVolumeSize, ebsRootVolumeIops, ebsRootVolumeThroughput and releaseLabel

Open haeganm opened this issue 1 month ago • 1 comments

Describe the bug

EmrCreateCluster throws at synth when ebsRootVolumeSize, ebsRootVolumeIops or ebsRootVolumeThroughput is a token, like sfn.JsonPath.numberAt('$.iops').

The range checks in validatePropsRelatedToReleaseLabel() compare the raw number without a Token.isUnresolved() guard. Number tokens encode as a huge negative double (-1.888e+289), so the lower bound check is always true and every tokenized value gets rejected.

Same thing for releaseLabel. If it's a token and ebsRootVolumeIops or ebsRootVolumeThroughput is set, semver.lt() gets called on the token string and crashes with a plain TypeError: Invalid Version.

The rest of that method already handles tokens. releaseLabel and stepConcurrencyLevel are both guarded, and the test file has Create Cluster with an unresolved release label and a stepConcurrencyLevel "can be set dynamically through JsonPath" test. The ebs checks were added later in #34677 without the guard.

Regression Issue

  • [x] Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

2.215.0 (for ebsRootVolumeSize and releaseLabel. ebsRootVolumeIops / ebsRootVolumeThroughput didn't exist before 2.216.0)

Expected Behavior

Tokenized values skip the synth-time range checks and render as JsonPath parameters, like StepConcurrencyLevel.$ already does. On 2.215.0, ebsRootVolumeSize: Size.gibibytes(JsonPath.numberAt('$.size')) renders "EbsRootVolumeSize.$": "$.size".

Current Behavior

On 2.275.0:

THREW | ebsRootVolumeIops = JsonPath.numberAt | ValidationError: ebsRootVolumeIops must be between 3000 and 16000, but got -1.8881545897087511e+289.
THREW | ebsRootVolumeThroughput = JsonPath.numberAt | ValidationError: ebsRootVolumeThroughput must be between 125 and 1000 MiB/s, but got -1.8881545897087513e+289 MiB/s.
THREW | ebsRootVolumeSize = Size.gibibytes(JsonPath.numberAt) | ValidationError: ebsRootVolumeSize must be between 15 and 100 GiB, but got -1.8881545897087516e+289 GiB.
THREW | releaseLabel = JsonPath.stringAt + literal ebsRootVolumeIops | TypeError: Invalid Version: ken[release.9]}
OK    | control: stepConcurrencyLevel = JsonPath.numberAt | StepConcurrencyLevel.$="$.steps"
THREW | control: literal ebsRootVolumeIops 99999 | ValidationError: ebsRootVolumeIops must be between 3000 and 16000, but got 99999.

Same script on 2.215.0:

OK    | ebsRootVolumeSize = Size.gibibytes(JsonPath.numberAt) | EbsRootVolumeSize.$="$.size"
OK    | releaseLabel = JsonPath.stringAt + literal ebsRootVolumeIops | ReleaseLabel.$="$.release"
OK    | control: stepConcurrencyLevel = JsonPath.numberAt | StepConcurrencyLevel.$="$.steps"

Reproduction Steps

node repro.js <path to aws-cdk-lib>

const cdk = require(process.argv[2]);
const sfn = cdk.aws_stepfunctions;
const tasks = cdk.aws_stepfunctions_tasks;

const cases = {
  'ebsRootVolumeIops = JsonPath.numberAt': { ebsRootVolumeIops: sfn.JsonPath.numberAt('$.iops') },
  'ebsRootVolumeThroughput = JsonPath.numberAt': { ebsRootVolumeThroughput: sfn.JsonPath.numberAt('$.throughput') },
  'ebsRootVolumeSize = Size.gibibytes(JsonPath.numberAt)': { ebsRootVolumeSize: cdk.Size.gibibytes(sfn.JsonPath.numberAt('$.size')) },
  'releaseLabel = JsonPath.stringAt + literal ebsRootVolumeIops': { releaseLabel: sfn.JsonPath.stringAt('$.release'), ebsRootVolumeIops: 4000 },
  'control: stepConcurrencyLevel = JsonPath.numberAt': { stepConcurrencyLevel: sfn.JsonPath.numberAt('$.steps') },
  'control: literal ebsRootVolumeIops 99999': { ebsRootVolumeIops: 99999 },
};

for (const [name, extra] of Object.entries(cases)) {
  const stack = new cdk.Stack();
  try {
    const task = new tasks.EmrCreateCluster(stack, 'Task', { instances: {}, name: 'cluster', ...extra });
    const params = stack.resolve(task.toStateJson()).Parameters;
    const keys = Object.keys(params).filter(k => /EbsRoot|ReleaseLabel|StepConcurrency/.test(k));
    console.log(`OK    | ${name} | ${keys.map(k => `${k}=${JSON.stringify(params[k])}`).join(' ')}`);
  } catch (e) {
    console.log(`THREW | ${name} | ${e.constructor.name}: ${e.message.split('\n')[0]}`);
  }
}

Possible Solution

Add Token.isUnresolved() guards to the three range checks and the semver.lt() release label check, same as the stepConcurrencyLevel block above them. Literal values keep the exact same validation. Fix ready, PR to follow.

Additional Information/Context

The checks came in with #34677 (first released in 2.216.0).

AWS CDK Library version (aws-cdk-lib)

2.275.0

AWS CDK CLI version

not used, the repro calls stack.resolve() directly with node

Node.js Version

v25.3.0

OS

macOS 26.6.2

Language

TypeScript

Language Version

plain JavaScript repro against the compiled aws-cdk-lib

Other information

No response

haeganm avatar Nov 04 '26 19:11 haeganm

Hi @haeganm,

The cause is the EBS range checks in validatePropsRelatedToReleaseLabel() (added in 2.216.0). They do not skip token placeholders, so ebsRootVolumeSize, ebsRootVolumeIops, and ebsRootVolumeThroughput fail at synth time when passed as JsonPath tokens. stepConcurrencyLevel works because it has a token guard.

Reproduced with cdk synth:

  • 2.275.0 (reported and latest): fails
  • 2.216.0: fails
  • 2.215.0: works

A fix is in PR #39647, which is open. It is waiting on the integration test requirement from the PR linter.

Until then, a workaround is to set the state's DefinitionString with CfnStateMachinePropsMixin. It synthesizes on 2.275.0. Remove the EBS props from the EmrCreateCluster call first, then set the EBS fields through the Mixin as shown below.

const sfn = require('aws-cdk-lib/aws-stepfunctions');
const tasks = require('aws-cdk-lib/aws-stepfunctions-tasks');
const { CfnStateMachinePropsMixin } = require('@aws-cdk/cfn-property-mixins/aws-stepfunctions');

const task = new tasks.EmrCreateCluster(stack, 'CreateCluster', {
  name: 'triage-39646',
  instances, // your EMR instance groups
  releaseLabel: sfn.JsonPath.stringAt('$.releaseLabel'),
  stepConcurrencyLevel: sfn.JsonPath.numberAt('$.concurrency'),
  resultPath: '$.cluster',
});

const sm = new sfn.StateMachine(stack, 'StateMachine', {
  definitionBody: sfn.DefinitionBody.fromChainable(task),
  stateMachineName: 'triage-39646',
});

const state = task.toStateJson();
state.Parameters = {
  ...state.Parameters,
  'EbsRootVolumeSize.$': '$.size',
  'EbsRootVolumeIops.$': '$.iops',
  'EbsRootVolumeThroughput.$': '$.throughput',
};
state.End = true;

const definition = stack.toJsonString({
  StartAt: 'CreateCluster',
  States: { CreateCluster: state },
});

sm.node.defaultChild.with(new CfnStateMachinePropsMixin({ definitionString: definition }));

Install @aws-cdk/[email protected] alongside [email protected]. Replace the $.size, $.iops, and $.throughput paths with the input paths your state uses.

pahud avatar Nov 05 '26 20:11 pahud