Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

(aws_batch): The default value of Launch Template is default but should be latest #28137

Open
gmarchand opened this issue Nov 26, 2023 · 2 comments
Labels
@aws-cdk/aws-batch Related to AWS Batch bug This issue is a bug. effort/medium Medium work item – several days of effort p3

Comments

@gmarchand
Copy link

Describe the bug

The property of Compute Environment > LaunchTemplateSpecification > Version is set by the module aws-batch as Default. But when I update the launch template with CDK. The module selects the first version not the latest

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-batch-computeenvironment-launchtemplatespecification.html

The version number of the launch template, $Latest, or $Default.
If the value is $Latest, the latest version of the launch template is used. If the value is $Default, the default version of the launch template is used.

Expected Behavior

The Module aws-batch should set Compute Environment > LaunchTemplateSpecification > Version to $Latest

Current Behavior

The property of Compute Environment > LaunchTemplateSpecification > Version is set by the module aws-batch as Default.

Reproduction Steps

            multipart_user_data = ec2.MultipartUserData()
            with open(from_root("cdk", "constructs", "user_data_xray.txt")) as f:
                user_data_xray_txt = f.read()
                multipart_user_data.add_part(
                    ec2.MultipartBody.from_raw_body(
                        content_type='text/x-shellscript; charset="us-ascii"',
                        body=user_data_xray_txt,
                    )
                )
            launch_template = ec2.LaunchTemplate(
                self,
                "lt-" + proc_name,
                launch_template_name="batch-ffmpeg-lt-" + proc_name,
                user_data=multipart_user_data,
            )
            compute_environment = batch.ManagedEc2EcsComputeEnvironment(
                self,
                "batch-ec2-compute-environment-" + proc_name,
                vpc=ec2_vpc,
                images=[{"image": ec2_ami}],
                instance_classes=batch_compute_instance_classes,
                use_optimal_instance_classes=False,
                update_to_latest_image_version=True,
                instance_role=batch_compute_env_instance_role,
                terminate_on_update=False,
                launch_template=launch_template,
                security_groups=[ec2_vpc_sg],
                vpc_subnets=ec2_vpc_subnets,
                spot=True,
                spot_bid_percentage=100,
                maxv_cpus=4096,
            )

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.110.1 (build 0d37f0d)

Framework Version

No response

Node.js Version

v18.0.0

OS

Macos

Language

Python

Language Version

No response

Other information

No response

@gmarchand gmarchand added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 26, 2023
@github-actions github-actions bot added the @aws-cdk/aws-batch Related to AWS Batch label Nov 26, 2023
@pahud pahud self-assigned this Nov 27, 2023
@pahud pahud added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Nov 27, 2023
@pahud
Copy link
Contributor

pahud commented Nov 27, 2023

Yes it doesn't seem to allow us to specify the version.

A workaround is to addPropertyOverride it like this using escape hatches.

    const lt = new ec2.LaunchTemplate(this, 'LT');

    const compuEnv = new batch.ManagedEc2EcsComputeEnvironment(this, 'MyEnv', {
      vpc,
      launchTemplate: lt,
    });
    const cfnEnv = compuEnv.node.tryFindChild('Resource') as batch.CfnComputeEnvironment;
    cfnEnv.addPropertyOverride('ComputeResources.LaunchTemplate.Version', lt.latestVersionNumber);

And when you cdk synth make sure you see the Version prop of the LaunchTemplate:

 "MyEnvF6A4DA2E": {
   "Type": "AWS::Batch::ComputeEnvironment",
   "Properties": {
    "ComputeResources": {
     "AllocationStrategy": "BEST_FIT_PROGRESSIVE",
     "InstanceRole": {
      "Fn::GetAtt": [
       "MyEnvInstanceProfileD2500C22",
       "Arn"
      ]
     },
     "InstanceTypes": [
      "optimal"
     ],
     "LaunchTemplate": {
      "LaunchTemplateId": {
       "Ref": "LTC4631592"
      },
      "Version": {
       "Fn::GetAtt": [
        "LTC4631592",
        "LatestVersionNumber"
       ]
      }
     },

@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Nov 27, 2023
@pahud pahud removed their assignment Nov 27, 2023
@pahud pahud removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels Nov 27, 2023
@pahud pahud added p3 and removed p2 labels Jun 11, 2024
@IllarionovDimitri
Copy link

IllarionovDimitri commented Jul 24, 2024

just had the same issue, in Batch $Default version of launch template is defined which kinda makes no sense if i want to update smth in instance config. defining a version (at least ENUM like .DEFAULT or .LATEST) would be helpful.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
@aws-cdk/aws-batch Related to AWS Batch bug This issue is a bug. effort/medium Medium work item – several days of effort p3
Projects
None yet
Development

No branches or pull requests

3 participants