diff --git a/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts b/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts index 53bf6b7fb32fd..0c2c36d1b18a7 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts @@ -1414,7 +1414,7 @@ export class InstanceType { } public sameInstanceClassAs(other: InstanceType): boolean { - const instanceClass: RegExp = /^([a-z]+\d{1,2}[a-z]*)\.([a-z0-9]+)$/; + const instanceClass: RegExp = /^([a-z-]+\d{1,2}[a-z-]*)\.([a-z0-9-]+)$/; const instanceClassId = this.instanceTypeIdentifier.match(instanceClass); const otherInstanceClassId = other.instanceTypeIdentifier.match(instanceClass); if (instanceClassId == null || otherInstanceClassId == null) { diff --git a/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts b/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts index 3dcde47e3b5a8..f656ec0c3553d 100644 --- a/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts +++ b/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts @@ -679,6 +679,15 @@ test('sameInstanceClassAs compares identical InstanceTypes correctly', () => { expect(sameInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy(); }); +test('sameInstanceClassAs compares identical InstanceTypes correctly', () => { + // GIVEN + const comparitor = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.LARGE); + //WHEN + const instanceType = new InstanceType('m7i-flex.large'); + //THEN + expect(instanceType.sameInstanceClassAs(comparitor)).toBeTruthy(); +}); + test('sameInstanceClassAs compares InstanceTypes correctly regardless of size', () => { // GIVEN const comparitor = InstanceType.of(InstanceClass.T3, InstanceSize.LARGE);