Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ new ManagedEc2EcsComputeEnvironment(stack, 'ECS_AL2023', {
}],
});

new ManagedEc2EcsComputeEnvironment(stack, 'ECS_AL2023_NVIDIA', {
vpc,
images: [{
imageType: EcsMachineImageType.ECS_AL2023_NVIDIA,
}],
});

new ManagedEc2EcsComputeEnvironment(stack, 'ParamertizedManagedCE', {
vpc,
images: [{
Expand Down
17 changes: 11 additions & 6 deletions packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export interface EcsMachineImage extends MachineImage {
/**
* A Batch MachineImage that is compatible with EKS
*/
export interface EksMachineImage extends MachineImage{
export interface EksMachineImage extends MachineImage {
/**
* Tells Batch which instance type to launch this image on
*
Expand All @@ -413,9 +413,14 @@ export enum EcsMachineImageType {
ECS_AL2023 = 'ECS_AL2023',

/**
* Tells Batch that this machine image runs on GPU instances
* Tells Batch that this machine image runs on GPU AL2 instances
*/
ECS_AL2_NVIDIA = 'ECS_AL2_NVIDIA',

/**
* Tells Batch that this machine image runs on GPU AL2023 instances
*/
ECS_AL2023_NVIDIA = 'ECS_AL2023_NVIDIA',
}

/**
Expand Down Expand Up @@ -652,7 +657,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
public readonly instanceClasses = [];
public readonly instanceTypes = [];
public readonly maxvCpus = 1;
public readonly connections = { } as any;
public readonly connections = {} as any;
public readonly securityGroups = [];
public readonly tags: TagManager = new TagManager(TagType.MAP, 'AWS::Batch::ComputeEnvironment');

Expand Down Expand Up @@ -703,9 +708,9 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa

this.instanceTypes = props.instanceTypes ?? [];
this.instanceClasses = props.instanceClasses ?? [];
if (this.images?.find(image => image.imageType === EcsMachineImageType.ECS_AL2023) &&
if (this.images?.find(image => image.imageType === EcsMachineImageType.ECS_AL2023 || image.imageType === EcsMachineImageType.ECS_AL2023_NVIDIA) &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if( [ EcsMachineImageType.ECS_AL2023, EcsMachineImageType.ECS_AL2023_NVIDIA ].includes(image.imageType)) ...`

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XaaXaaX
Thanks for your review comment!
I think your suggestion is better than the current code, so I’ve applied it.

(this.instanceClasses.includes(ec2.InstanceClass.A1) ||
this.instanceTypes.find(instanceType => instanceType.sameInstanceClassAs(ec2.InstanceType.of(ec2.InstanceClass.A1, ec2.InstanceSize.LARGE))))
this.instanceTypes.find(instanceType => instanceType.sameInstanceClassAs(ec2.InstanceType.of(ec2.InstanceClass.A1, ec2.InstanceSize.LARGE))))
) {
throw new ValidationError('Amazon Linux 2023 does not support A1 instances.', this);
}
Expand Down Expand Up @@ -1182,7 +1187,7 @@ export class FargateComputeEnvironment extends ManagedComputeEnvironmentBase imp
public readonly computeEnvironmentName = computeEnvironmentName;
public readonly enabled = true;
public readonly maxvCpus = 1;
public readonly connections = { } as any;
public readonly connections = {} as any;
public readonly securityGroups = [];
public readonly tags: TagManager = new TagManager(TagType.MAP, 'AWS::Batch::ComputeEnvironment');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,32 @@ describe('ManagedEc2EcsComputeEnvironment', () => {
});
});

test('image types are correctly rendered as EC2ConfigurationObjects for AL2023_NVIDIA', () => {
// WHEN
new ManagedEc2EcsComputeEnvironment(stack, 'MyCE', {
...defaultEcsProps,
vpc,
images: [
{
imageType: EcsMachineImageType.ECS_AL2023_NVIDIA,
},
],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', {
...pascalCaseExpectedEcsProps,
ComputeResources: {
...defaultComputeResources,
Ec2Configuration: [
{
ImageType: 'ECS_AL2023_NVIDIA',
},
],
},
});
});

test('Amazon Linux 2023 does not support A1 instances.', () => {
expect(() => new ManagedEc2EcsComputeEnvironment(stack, 'Al2023A1InstanceClass', {
...defaultEcsProps,
Expand All @@ -947,6 +973,28 @@ describe('ManagedEc2EcsComputeEnvironment', () => {
],
})).toThrow('Amazon Linux 2023 does not support A1 instances.');

expect(() => new ManagedEc2EcsComputeEnvironment(stack, 'Al2023NvidiaA1InstanceClass', {
...defaultEcsProps,
instanceClasses: [ec2.InstanceClass.A1],
vpc,
images: [
{
imageType: EcsMachineImageType.ECS_AL2023_NVIDIA,
},
],
})).toThrow('Amazon Linux 2023 does not support A1 instances.');

expect(() => new ManagedEc2EcsComputeEnvironment(stack, 'Al2023NvidiaA1XlargeInstance', {
...defaultEcsProps,
instanceTypes: [ec2.InstanceType.of(ec2.InstanceClass.A1, ec2.InstanceSize.XLARGE2)],
vpc,
images: [
{
imageType: EcsMachineImageType.ECS_AL2023_NVIDIA,
},
],
})).toThrow('Amazon Linux 2023 does not support A1 instances.');

new ManagedEc2EcsComputeEnvironment(stack, 'Al2A1InstanceClass', {
...defaultEcsProps,
instanceClasses: [ec2.InstanceClass.A1],
Expand Down
Loading