Skip to content

Commit

Permalink
fix(batch): support cfn parameters for managed compute environment pr…
Browse files Browse the repository at this point in the history
…operties minvcpus, maxvcpus, and spotbidpercentage (#32954)

### Issue # (if applicable)

Closes #32905.

### Reason for this change

The Aws Batch Managed Compute Environment L2 currently does not allow for CfnParameter / Tokens for numeric properties that perform validation at synth time. This is a common pattern in other L2's in AWS CDK to skip the validation checks if the property can support being a cloud formation parameter

### Description of changes

I updated the validation methods in ManagedComputeEnvironment to skip if the property being validated is a token. Affected properties are spotBidPercentage, minVCpus, and maxVCpus. The logic keeps performing any of the checks if enough information in any of the properties are there to do the check at synth time.

### Describe any new or updated permissions being added

N/A

### Description of how you validated changes

Added new unit tests

### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
bdoyle0182 authored Jan 29, 2025
1 parent 6fa1d05 commit 5fef9e0
Show file tree
Hide file tree
Showing 10 changed files with 632 additions and 88 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,23 @@
}
}
},
"SpotFleetRole6D4F7558": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "batch.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"minimalPropsFargateSecurityGroupA8D5CDD1": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
Expand Down Expand Up @@ -751,23 +768,6 @@
}
}
},
"SpotFleetRole6D4F7558": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "batch.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"SpotEc2SecurityGroup1225E163": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
Expand Down Expand Up @@ -1220,13 +1220,146 @@
"Type": "managed",
"UpdatePolicy": {}
}
},
"ParamertizedManagedCESecurityGroup772BD71B": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "batch-stack/ParamertizedManagedCE/SecurityGroup",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow all outbound traffic by default",
"IpProtocol": "-1"
}
],
"VpcId": {
"Ref": "vpcA2121C38"
}
}
},
"ParamertizedManagedCEInstanceProfileRoleB54B7F8B": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
]
]
}
]
}
},
"ParamertizedManagedCEInstanceProfileDF9CB175": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Roles": [
{
"Ref": "ParamertizedManagedCEInstanceProfileRoleB54B7F8B"
}
]
}
},
"ParamertizedManagedCE07932AA8": {
"Type": "AWS::Batch::ComputeEnvironment",
"Properties": {
"ComputeResources": {
"AllocationStrategy": "SPOT_PRICE_CAPACITY_OPTIMIZED",
"BidPercentage": {
"Ref": "SpotBidPercentageParameter"
},
"Ec2Configuration": [
{
"ImageIdOverride": {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
},
"ImageType": "ECS_AL2"
}
],
"InstanceRole": {
"Fn::GetAtt": [
"ParamertizedManagedCEInstanceProfileDF9CB175",
"Arn"
]
},
"InstanceTypes": [
"optimal"
],
"MaxvCpus": {
"Ref": "MaxVCpuParameter"
},
"MinvCpus": {
"Ref": "MinVCpuParameter"
},
"SecurityGroupIds": [
{
"Fn::GetAtt": [
"ParamertizedManagedCESecurityGroup772BD71B",
"GroupId"
]
}
],
"SpotIamFleetRole": {
"Fn::GetAtt": [
"SpotFleetRole6D4F7558",
"Arn"
]
},
"Subnets": [
{
"Ref": "vpcPrivateSubnet1Subnet934893E8"
},
{
"Ref": "vpcPrivateSubnet2Subnet7031C2BA"
}
],
"Type": "SPOT"
},
"ReplaceComputeEnvironment": false,
"State": "ENABLED",
"Type": "managed",
"UpdatePolicy": {}
}
}
},
"Parameters": {
"SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
},
"MinVCpuParameter": {
"Type": "Number",
"Default": 512,
"MinValue": 0
},
"MaxVCpuParameter": {
"Type": "Number",
"Default": 512,
"MinValue": 1
},
"SpotBidPercentageParameter": {
"Type": "Number",
"Default": 100,
"MinValue": 1
},
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5fef9e0

Please sign in to comment.