Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

(batch): The following parameters can't be updated for Fargate compute environment thrown on fresh deployment #27054

Open
bhargav265 opened this issue Sep 7, 2023 · 5 comments
Labels
@aws-cdk/aws-batch Related to AWS Batch bug This issue is a bug. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p3

Comments

@bhargav265
Copy link

Describe the bug

We are using Fargate compute environment and we are unable to update the max vcpus on CFN.
We get the error

The following parameters can\'t be updated for Fargate compute environment: allocationStrategy, bidPercentage, ec2Configuration, ec2KeyPair, imageId, instanceRole, instanceTypes, launchTemplate, placementGroup, tags, type, updatePolicy, updateToLatestImageVersion. (Service: Batch, Status Code: 400, Request ID: 5bf1284d-eefb-42c1-921a-41e6d0b44565)

Expected Behavior

Should update the maxVcpus directly

Current Behavior

Throws the error

The following parameters can\'t be updated for Fargate compute environment: allocationStrategy, bidPercentage, ec2Configuration, ec2KeyPair, imageId, instanceRole, instanceTypes, launchTemplate, placementGroup, tags, type, updatePolicy, updateToLatestImageVersion. (Service: Batch, Status Code: 400, Request ID: 5bf1284d-eefb-42c1-921a-41e6d0b44565)

Reproduction Steps

  1. Make a Compute environment with some vcpu setting something like:
 new FargateComputeEnvironment(this, batchComputeEnvironmentName, {
            enabled: true,
            maxvCpus: 512,
            vpc: props.vpc,
            computeEnvironmentName: batchComputeEnvironmentName,
        });
  1. Deploy this to an AWS account
  2. Change the maxVcpu value to be 2048 or something different.
  3. Deploy again.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

V2

Framework Version

No response

Node.js Version

18.16.1

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

@bhargav265 bhargav265 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 7, 2023
@github-actions github-actions bot added the @aws-cdk/aws-batch Related to AWS Batch label Sep 7, 2023
@comcalvi comcalvi added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 7, 2023
@comcalvi
Copy link
Contributor

comcalvi commented Sep 7, 2023

root cause, provided by an internal engineer:

The CFN handler first calls createComputeEnvironment, and updateToLatestImageVersion is not passed in. Then the handler calls UpdateComputeEnvironment, which does pass this value in. Batch sees this as changing this value on an already-created CE, resulting in this error.

Fix: don't pass this value in by default anywhere.

There's a whole list of properties to which this applies, but the CDK shouldn't special-case Fargate CEs to deal with that. Instead this issue needs to be resolved at the CFN level.

@comcalvi comcalvi changed the title (@aws-cdk/aws-batch-alpha): (unable to update maxVcpus) (batch): The following parameters can't be updated for Fargate compute environment thrown on fresh deployment Sep 8, 2023
@comcalvi comcalvi added the needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. label Sep 8, 2023
mergify bot pushed a commit that referenced this issue Sep 9, 2023
graduates the alpha module.

All users of any `ManagedComputeEnvironment` who left `updateToLatestImageVersion` unspecified will see it default to `undefined` instead of `true`. *If you use `FargateComputeEnvironment`, this upgrade may cause deployment errors; destroy the Fargate CE and recreate it to resolve this, if encountered.* 


Related: #27054.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mikewrighton pushed a commit that referenced this issue Sep 14, 2023
graduates the alpha module.

All users of any `ManagedComputeEnvironment` who left `updateToLatestImageVersion` unspecified will see it default to `undefined` instead of `true`. *If you use `FargateComputeEnvironment`, this upgrade may cause deployment errors; destroy the Fargate CE and recreate it to resolve this, if encountered.* 


Related: #27054.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@polamjag
Copy link
Contributor

polamjag commented Sep 25, 2023

#27059 seems to be included in v2.96.0 release, but I'm still experiencing same error message as #27054 (comment) in v2.96.2.

To bad I have not yet found a workaround for this problem. Once I get into this situation, the deploy seems to fail even when no diffs are generated.

@dschulz-aam
Copy link

dschulz-aam commented Sep 26, 2023

I still seem to be having this issue, I changed the number of maxv_cpus from 5 to 8 for the following compute environment definition:

fargate_compute = batch.FargateComputeEnvironment(
    self,
    "FargateComputeEnv",
    compute_environment_name="FargateEnv",
    vpc=vpc,
    maxv_cpus=8,
)

I get this error with cdk v 2.97.0:

"The following parameters can\'t be updated for Fargate compute environment: allocationStrategy, bidPercentage, ec2Configuration, ec2KeyPair, imageId, instanceRole, instanceTypes, launchTemplate, placementGroup, tags, type, updatePolicy, updateToLatestImageVersion. (Service: Batch, Status Code: 400, Request ID: 6e88dfba-ac1a-4e34-8b43-7c74f2270c14)" (RequestToken: e63bbbad-2be2-0b81-2714-30cd9f04437c, HandlerErrorCode: InvalidRequest)

@wafuwafu13
Copy link
Contributor

wafuwafu13 commented Sep 26, 2023

In CFn, I reproduce it when ReplaceComputeEnvironment is false.
In CFn, the default value is true, but false in CDK.

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

ReplaceComputeEnvironment
Specifies whether the compute environment is replaced if an update is made that requires replacing the instances in the compute environment. The default value is true.

this.replaceComputeEnvironment = props.replaceComputeEnvironment ?? false;

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  ComputeEnvironment:
    Type: AWS::Batch::ComputeEnvironment
    Properties: 
      ComputeEnvironmentName: "issue27054"
      ComputeResources:
        Type: "FARGATE"
        MaxvCpus: 128
        SecurityGroupIds:
          - sg-xxx
        Subnets:
          - subnet-xxx
          - subnet-xxx
      Type: "MANAGED"

=> CREATE_COMPLETE

MaxvCpus: 256

=> UPDATE_COMPLETE

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  ComputeEnvironment:
    Type: AWS::Batch::ComputeEnvironment
    Properties: 
      ComputeEnvironmentName: "issue27054"
      ComputeResources:
        Type: "FARGATE"
        MaxvCpus: 128
        SecurityGroupIds:
          - sg-xxx
        Subnets:
          - subnet-xxx
          - subnet-xxx
      Type: "MANAGED"
      ReplaceComputeEnvironment: false

=> CREATE_COMPLETE

MaxvCpus: 256

=> UPDATE_FAILED

Resource handler returned message: "The following parameters can\'t be updated for Fargate compute environment: allocationStrategy, bidPercentage, ec2Configuration, ec2KeyPair, imageId, instanceRole, instanceTypes, launchTemplate, placementGroup, tags, type, updatePolicy, updateToLatestImageVersion. (Service: Batch, Status Code: 400, Request ID: xxx)" (RequestToken: xxx, HandlerErrorCode: InvalidRequest)

@wafuwafu13
Copy link
Contributor

wafuwafu13 commented Sep 27, 2023

@comcalvi

This doesn't seem to be a CFN issue, and the problem seems to be that replacecomputeEnvironment is false by default in CDK (please see above).

It seems that we can work around this by passing replaceComputeEnvironment: true to the FargateComputeEnvironment constructor (please see below).

(I'm not sure why it's false by default in CDK.)

from aws_cdk import (
                     aws_ec2 as ec2, 
                     aws_batch as batch,
                     App, Stack
                     )
from constructs import Construct

class Issue27054Stack(Stack):

    def __init__(self, scope: Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)
        vpc = ec2.Vpc(self, "VPC")

        name = "issue27054"
        batch.FargateComputeEnvironment(self, name,
            vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS),
            vpc=vpc,
            maxv_cpus=128,
            replace_compute_environment=True
        )

app = App()
Issue27054Stack(app, "Issue27054Stack")
app.synth()

=> CREATE_COMPLETE

maxv_cpus=256
$ cdk diff
Stack Issue27054Stack
Resources
[~] AWS::Batch::ComputeEnvironment issue27054 issue27054AF17756A 
 └─ [~] ComputeResources
     └─ [~] .MaxvCpus:
         ├─ [-] 128
         └─ [+] 256


✨  Number of stacks with differences: 1

=> UPDATE_COMPLETE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-batch Related to AWS Batch bug This issue is a bug. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p3
Projects
None yet
Development

No branches or pull requests

6 participants