diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/batch/submit-job.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/batch/submit-job.ts index e0780b0b26b09..d795b9f62f5e2 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/batch/submit-job.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/batch/submit-job.ts @@ -1,7 +1,7 @@ import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; -import { Size, Stack, withResolved } from '@aws-cdk/core'; +import { Size, Stack, Token, withResolved } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { integrationResourceArn, validatePatternSupported } from '../private/task-utils'; @@ -191,11 +191,17 @@ export class BatchSubmitJob extends sfn.TaskStateBase { }); // validate timeout - props.timeout !== undefined && withResolved(props.timeout.toSeconds(), (timeout) => { - if (timeout < 60) { - throw new Error(`attempt duration must be greater than 60 seconds. Received ${timeout} seconds.`); - } - }); + if (props.timeout !== undefined && !props.timeout.isUnresolved() && props.timeout.toSeconds() < 60) { + throw new Error(`attempt duration must be at least 60 seconds. Received ${props.timeout} seconds.`); + } + + // validate memory + if (props.containerOverrides?.memory !== undefined && + !props.containerOverrides.memory.isUnresolved() && + props.containerOverrides.memory.toMebibytes() < 4) { + throw new Error('memory must be at least 4MiB'); + } + // This is required since environment variables must not start with AWS_BATCH; // this naming convention is reserved for variables that are set by the AWS Batch service. @@ -296,7 +302,7 @@ export class BatchSubmitJob extends sfn.TaskStateBase { resources.push( { Type: 'GPU', - Value: `${containerOverrides.gpuCount}`, + Value: tokenOrString(containerOverrides.gpuCount), }, ); } @@ -304,7 +310,7 @@ export class BatchSubmitJob extends sfn.TaskStateBase { resources.push( { Type: 'MEMORY', - Value: `${containerOverrides.memory.toMebibytes()}`, + Value: tokenOrString(containerOverrides.memory.toMebibytes()), }, ); } @@ -312,7 +318,7 @@ export class BatchSubmitJob extends sfn.TaskStateBase { resources.push( { Type: 'VCPU', - Value: `${containerOverrides.vcpus}`, + Value: tokenOrString(containerOverrides.vcpus), }, ); } @@ -325,3 +331,7 @@ export class BatchSubmitJob extends sfn.TaskStateBase { }; } } + +function tokenOrString(value: any) { + return Token.isUnresolved(value) ? value : value.toString(); +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/batch/submit-job.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/batch/submit-job.test.ts index 0885dcfb55930..4d7581a4f3829 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/batch/submit-job.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/batch/submit-job.test.ts @@ -134,6 +134,11 @@ test('supports tokens', () => { arraySize: sfn.JsonPath.numberAt('$.arraySize'), timeout: cdk.Duration.seconds(sfn.JsonPath.numberAt('$.timeout')), attempts: sfn.JsonPath.numberAt('$.attempts'), + containerOverrides: { + gpuCount: sfn.JsonPath.numberAt('$.gpuCount'), + memory: cdk.Size.mebibytes(sfn.JsonPath.numberAt('$.memory')), + vcpus: sfn.JsonPath.numberAt('$.vcpus'), + }, }); // THEN @@ -165,6 +170,22 @@ test('supports tokens', () => { 'Timeout': { 'AttemptDurationSeconds.$': '$.timeout', }, + 'ContainerOverrides': { + ResourceRequirements: [ + { + 'Type': 'GPU', + 'Value.$': '$.gpuCount', + }, + { + 'Type': 'MEMORY', + 'Value.$': '$.memory', + }, + { + 'Type': 'VCPU', + 'Value.$': '$.vcpus', + }, + ], + }, }, }); });