diff --git a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts index dd6cc425e23e0..7b5c6a1cdf7c4 100644 --- a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts +++ b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts @@ -719,6 +719,16 @@ export class Job extends JobBase { } } + if (props.maxCapacity !== undefined && (props.workerType && props.workerCount !== undefined)) { + throw new Error('maxCapacity cannot be used when setting workerType and workerCount'); + } + if (props.maxCapacity !== undefined && ![GlueVersion.V0_9, GlueVersion.V1_0].includes(executable.glueVersion)) { + throw new Error('maxCapacity cannot be used when GlueVersion 2.0 or later'); + } + if ((!props.workerType && props.workerCount !== undefined) || (props.workerType && props.workerCount === undefined)) { + throw new Error('Both workerType and workerCount must be set'); + } + const jobResource = new CfnJob(this, 'Resource', { name: props.jobName, description: props.description, diff --git a/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts b/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts index 59316670b0410..cdb5a838fba09 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts +++ b/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts @@ -1049,5 +1049,53 @@ describe('Job', () => { })); }); }); + + describe('validation for maxCapacity and workerType', () => { + test('maxCapacity with workerType and workerCount should throw', () => { + expect(() => new glue.Job(stack, 'Job', { + executable: glue.JobExecutable.pythonEtl({ + glueVersion: glue.GlueVersion.V1_0, + pythonVersion: glue.PythonVersion.THREE, + script, + }), + maxCapacity: 10, + workerType: glue.WorkerType.G_1X, + workerCount: 10, + })).toThrow('maxCapacity cannot be used when setting workerType and workerCount'); + }); + + test('maxCapacity with GlueVersion 2.0 or later should throw', () => { + expect(() => new glue.Job(stack, 'Job', { + executable: glue.JobExecutable.pythonEtl({ + glueVersion: glue.GlueVersion.V2_0, + pythonVersion: glue.PythonVersion.THREE, + script, + }), + maxCapacity: 10, + })).toThrow('maxCapacity cannot be used when GlueVersion 2.0 or later'); + }); + + test('workerType without workerCount should throw', () => { + expect(() => new glue.Job(stack, 'Job', { + executable: glue.JobExecutable.pythonEtl({ + glueVersion: glue.GlueVersion.V2_0, + pythonVersion: glue.PythonVersion.THREE, + script, + }), + workerType: glue.WorkerType.G_1X, + })).toThrow('Both workerType and workerCount must be set'); + }); + + test('workerCount without workerType should throw', () => { + expect(() => new glue.Job(stack, 'Job', { + executable: glue.JobExecutable.pythonEtl({ + glueVersion: glue.GlueVersion.V2_0, + pythonVersion: glue.PythonVersion.THREE, + script, + }), + workerCount: 10, + })).toThrow('Both workerType and workerCount must be set'); + }); + }); }); });