Skip to content

Commit 0ab8c7c

Browse files
authored
chore(eks): error message for ami type (#28708)
Currently, if you select the wrong AMI type you get the following: ``` Error: The specified AMI does not match the instance types architecture, either specify one of AL2_x86_64, BOTTLEROCKET_x86_64, WINDOWS_CORE_2019_x86_64, WINDOWS_CORE_2022_x86_64, WINDOWS_FULL_2019_x86_64, WINDOWS_FULL_2022_x86_64 or don't specify any ``` IMO the error messages should give the enum values defined [here](https://github.com/aws/aws-cdk/blob/e25c5b6758068b561f55c4d7b2654d951e8ea313/packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts#L28-L73), not the string value. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1e69cc6 commit 0ab8c7c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export class Nodegroup extends Resource implements INodegroup {
421421

422422
// if the user explicitly configured an ami type, make sure it's included in the possibleAmiTypes
423423
if (props.amiType && !possibleAmiTypes.includes(props.amiType)) {
424-
throw new Error(`The specified AMI does not match the instance types architecture, either specify one of ${possibleAmiTypes.join(', ')} or don't specify any`);
424+
throw new Error(`The specified AMI does not match the instance types architecture, either specify one of ${possibleAmiTypes.join(', ').toUpperCase()} or don't specify any`);
425425
}
426426

427427
//if the user explicitly configured a Windows ami type, make sure the instanceType is allowed
@@ -611,7 +611,7 @@ function getPossibleAmiTypes(instanceTypes: InstanceType[]): NodegroupAmiType[]
611611
const architectures: Set<AmiArchitecture> = new Set(instanceTypes.map(typeToArch));
612612

613613
if (architectures.size === 0) { // protective code, the current implementation will never result in this.
614-
throw new Error(`Cannot determine any ami type comptaible with instance types: ${instanceTypes.map(i => i.toString).join(',')}`);
614+
throw new Error(`Cannot determine any ami type compatible with instance types: ${instanceTypes.map(i => i.toString).join(', ')}`);
615615
}
616616

617617
if (architectures.size > 1) {

packages/aws-cdk-lib/aws-eks/test/nodegroup.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ describe('node group', () => {
558558
new ec2.InstanceType('p3.large'),
559559
new ec2.InstanceType('g3.large'),
560560
],
561-
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_x86_64_GPU, BOTTLEROCKET_x86_64_NVIDIA, BOTTLEROCKET_ARM_64_NVIDIA or don't specify any/);
561+
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_X86_64_GPU, BOTTLEROCKET_X86_64_NVIDIA, BOTTLEROCKET_ARM_64_NVIDIA or don't specify any/);
562562
});
563563

564564
/**
@@ -580,7 +580,7 @@ describe('node group', () => {
580580
new ec2.InstanceType('c5.large'),
581581
new ec2.InstanceType('m5.large'),
582582
],
583-
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_x86_64, BOTTLEROCKET_x86_64, WINDOWS_CORE_2019_x86_64, WINDOWS_CORE_2022_x86_64, WINDOWS_FULL_2019_x86_64, WINDOWS_FULL_2022_x86_64 or don't specify any/);
583+
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_X86_64, BOTTLEROCKET_X86_64, WINDOWS_CORE_2019_X86_64, WINDOWS_CORE_2022_X86_64, WINDOWS_FULL_2019_X86_64, WINDOWS_FULL_2022_X86_64 or don't specify any/);
584584
});
585585

586586
test('throws when AmiType is Windows and forbidden instanceType is selected', () => {
@@ -619,7 +619,7 @@ describe('node group', () => {
619619
new ec2.InstanceType('c5.large'),
620620
new ec2.InstanceType('m5.large'),
621621
],
622-
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_x86_64, BOTTLEROCKET_x86_64, WINDOWS_CORE_2019_x86_64, WINDOWS_CORE_2022_x86_64, WINDOWS_FULL_2019_x86_64, WINDOWS_FULL_2022_x86_64 or don't specify any/);
622+
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_X86_64, BOTTLEROCKET_X86_64, WINDOWS_CORE_2019_X86_64, WINDOWS_CORE_2022_X86_64, WINDOWS_FULL_2019_X86_64, WINDOWS_FULL_2022_X86_64 or don't specify any/);
623623
});
624624

625625
test('throws when LaunchTemplate is undefined, amiType is BOTTLEROCKET_ARM_64_NVIDIA and instanceTypes are not GPU', () => {
@@ -637,7 +637,7 @@ describe('node group', () => {
637637
new ec2.InstanceType('c5.large'),
638638
new ec2.InstanceType('m5.large'),
639639
],
640-
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_x86_64, BOTTLEROCKET_x86_64, WINDOWS_CORE_2019_x86_64, WINDOWS_CORE_2022_x86_64, WINDOWS_FULL_2019_x86_64, WINDOWS_FULL_2022_x86_64 or don't specify any/);
640+
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_X86_64, BOTTLEROCKET_X86_64, WINDOWS_CORE_2019_X86_64, WINDOWS_CORE_2022_X86_64, WINDOWS_FULL_2019_X86_64, WINDOWS_FULL_2022_X86_64 or don't specify any/);
641641
});
642642

643643
test('throws when LaunchTemplate is undefined, amiType is BOTTLEROCKET_X86_64_NVIDIA and instanceTypes are not GPU', () => {
@@ -655,7 +655,7 @@ describe('node group', () => {
655655
new ec2.InstanceType('c5.large'),
656656
new ec2.InstanceType('m5.large'),
657657
],
658-
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_x86_64, BOTTLEROCKET_x86_64, WINDOWS_CORE_2019_x86_64, WINDOWS_CORE_2022_x86_64, WINDOWS_FULL_2019_x86_64, WINDOWS_FULL_2022_x86_64 or don't specify any/);
658+
})).toThrow(/The specified AMI does not match the instance types architecture, either specify one of AL2_X86_64, BOTTLEROCKET_X86_64, WINDOWS_CORE_2019_X86_64, WINDOWS_CORE_2022_X86_64, WINDOWS_FULL_2019_X86_64, WINDOWS_FULL_2022_X86_64 or don't specify any/);
659659
});
660660

661661
/**

0 commit comments

Comments
 (0)