aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws-batch: Malformed Instance Type thrown for new InstanceType("optimal") regardless of architecture

Open DaveMadsen opened this issue 1 year ago • 2 comments

Describe the bug

We use new InstanceType("optimal") in our platform for batch resources. In the past, this has "just worked." Now we are getting an error, Resolution error: Malformed instance type identifier. I expect this to "just work".

it looks like this commit broke us in 2.161.1. If I understand what is happening, a check was added to block optimal use (or at least warn against its use) on ARM64 instances, but it looks like the architecture check is breaking because optimal is not yet resolved into a valid architecture.

Regression Issue

  • [ ] Select this option if this issue appears to be a regression.

Last Known Working CDK Version

2.160.0

Expected Behavior

I am able to use new InstanceType("optimal") on x86-64 architecture.

Current Behavior

new InstanceType("optimal") throws Resolution error: Malformed instance type identifier` on all architectures.

Reproduction Steps

let instanceType = new InstanceType("optimal");

Possible Solution

"optimal" needs to resolve into the target instance types before doing the architecture check. Longer term, "optimal" should be deprecated/removed or expanded to ARM64 archs.

Additional Information/Context

No response

CDK CLI Version

2.161.1 (build 0a606c9)

Framework Version

No response

Node.js Version

v18.20.4

OS

Linux 5.10 x86_64

Language

TypeScript

Language Version

TypeScript ~4.7.4

Other information

No response

DaveMadsen avatar Oct 15 '24 16:10 DaveMadsen

Hi @DaveMadsen , thanks for reaching out.

this is what I found about 'Optimal' types in cdk docs-

https://github.com/aws/aws-cdk/tree/main/packages/aws-cdk-lib/aws-batch

Note: Batch does not allow specifying instance types or classes with different architectures. For example, InstanceClass.A1 cannot be specified alongside 'optimal', because A1 uses ARM and 'optimal' uses x86_64. You can specify both 'optimal' alongside several different instance types in the same compute environment:

I also deployed the cdk stack with CDK Version 2.160 and 2.162, both deployed successfully for me. Sharing the code and snippets -

CDK Version 2.160 - Typescript code -

    const vpc01 = ec2.Vpc.fromLookup(this, 'myVpc', {
      isDefault: true,
      });
      
    const computeEnvironment = new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
      instanceTypes: [ec2.InstanceType.of(ec2.InstanceClass.M5AD, ec2.InstanceSize.LARGE)],
      useOptimalInstanceClasses: true, // default
      vpc: vpc01,
    });

synthesized template snippet -

  "myEc2ComputeEnvF0625F52": {
   "Type": "AWS::Batch::ComputeEnvironment",
   "Properties": {
    "ComputeResources": {
     "AllocationStrategy": "BEST_FIT_PROGRESSIVE",
     "InstanceRole": {
      "Fn::GetAtt": [
       "myEc2ComputeEnvInstanceProfileEACE4CE2",
       "Arn"
      ]
     },
     "InstanceTypes": [
      "m5ad.large",
      "optimal"
     ],
     "MaxvCpus": 256,
     "MinvCpus": 0,
     "SecurityGroupIds": [
      {
       "Fn::GetAtt": [
        "myEc2ComputeEnvSecurityGroupD0EB1CF5",
        "GroupId"
       ]
      }
     ],

Same code deployed with CDK Version 2.162.0 and it deployed successfully -

Screenshot 2024-10-17 at 2 29 55 PM

I think this is what you are trying to do. Please feel free to correct if this is misunderstood.

Also would request you to please share a self contained minimal repro code for the above mentioned issue as I am not able to repro it on my side.

khushail avatar Oct 17 '24 21:10 khushail

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Oct 20 '24 00:10 github-actions[bot]