Skip to content

Commit 5fef9e0

Browse files
authored
fix(batch): support cfn parameters for managed compute environment properties 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*
1 parent 6fa1d05 commit 5fef9e0

File tree

10 files changed

+632
-88
lines changed

10 files changed

+632
-88
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/BatchManagedComputeEnvironmentTestDefaultTestDeployAssertD4528F80.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json

+150-17
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@
391391
}
392392
}
393393
},
394+
"SpotFleetRole6D4F7558": {
395+
"Type": "AWS::IAM::Role",
396+
"Properties": {
397+
"AssumeRolePolicyDocument": {
398+
"Statement": [
399+
{
400+
"Action": "sts:AssumeRole",
401+
"Effect": "Allow",
402+
"Principal": {
403+
"Service": "batch.amazonaws.com"
404+
}
405+
}
406+
],
407+
"Version": "2012-10-17"
408+
}
409+
}
410+
},
394411
"minimalPropsFargateSecurityGroupA8D5CDD1": {
395412
"Type": "AWS::EC2::SecurityGroup",
396413
"Properties": {
@@ -751,23 +768,6 @@
751768
}
752769
}
753770
},
754-
"SpotFleetRole6D4F7558": {
755-
"Type": "AWS::IAM::Role",
756-
"Properties": {
757-
"AssumeRolePolicyDocument": {
758-
"Statement": [
759-
{
760-
"Action": "sts:AssumeRole",
761-
"Effect": "Allow",
762-
"Principal": {
763-
"Service": "batch.amazonaws.com"
764-
}
765-
}
766-
],
767-
"Version": "2012-10-17"
768-
}
769-
}
770-
},
771771
"SpotEc2SecurityGroup1225E163": {
772772
"Type": "AWS::EC2::SecurityGroup",
773773
"Properties": {
@@ -1220,13 +1220,146 @@
12201220
"Type": "managed",
12211221
"UpdatePolicy": {}
12221222
}
1223+
},
1224+
"ParamertizedManagedCESecurityGroup772BD71B": {
1225+
"Type": "AWS::EC2::SecurityGroup",
1226+
"Properties": {
1227+
"GroupDescription": "batch-stack/ParamertizedManagedCE/SecurityGroup",
1228+
"SecurityGroupEgress": [
1229+
{
1230+
"CidrIp": "0.0.0.0/0",
1231+
"Description": "Allow all outbound traffic by default",
1232+
"IpProtocol": "-1"
1233+
}
1234+
],
1235+
"VpcId": {
1236+
"Ref": "vpcA2121C38"
1237+
}
1238+
}
1239+
},
1240+
"ParamertizedManagedCEInstanceProfileRoleB54B7F8B": {
1241+
"Type": "AWS::IAM::Role",
1242+
"Properties": {
1243+
"AssumeRolePolicyDocument": {
1244+
"Statement": [
1245+
{
1246+
"Action": "sts:AssumeRole",
1247+
"Effect": "Allow",
1248+
"Principal": {
1249+
"Service": "ec2.amazonaws.com"
1250+
}
1251+
}
1252+
],
1253+
"Version": "2012-10-17"
1254+
},
1255+
"ManagedPolicyArns": [
1256+
{
1257+
"Fn::Join": [
1258+
"",
1259+
[
1260+
"arn:",
1261+
{
1262+
"Ref": "AWS::Partition"
1263+
},
1264+
":iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
1265+
]
1266+
]
1267+
}
1268+
]
1269+
}
1270+
},
1271+
"ParamertizedManagedCEInstanceProfileDF9CB175": {
1272+
"Type": "AWS::IAM::InstanceProfile",
1273+
"Properties": {
1274+
"Roles": [
1275+
{
1276+
"Ref": "ParamertizedManagedCEInstanceProfileRoleB54B7F8B"
1277+
}
1278+
]
1279+
}
1280+
},
1281+
"ParamertizedManagedCE07932AA8": {
1282+
"Type": "AWS::Batch::ComputeEnvironment",
1283+
"Properties": {
1284+
"ComputeResources": {
1285+
"AllocationStrategy": "SPOT_PRICE_CAPACITY_OPTIMIZED",
1286+
"BidPercentage": {
1287+
"Ref": "SpotBidPercentageParameter"
1288+
},
1289+
"Ec2Configuration": [
1290+
{
1291+
"ImageIdOverride": {
1292+
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
1293+
},
1294+
"ImageType": "ECS_AL2"
1295+
}
1296+
],
1297+
"InstanceRole": {
1298+
"Fn::GetAtt": [
1299+
"ParamertizedManagedCEInstanceProfileDF9CB175",
1300+
"Arn"
1301+
]
1302+
},
1303+
"InstanceTypes": [
1304+
"optimal"
1305+
],
1306+
"MaxvCpus": {
1307+
"Ref": "MaxVCpuParameter"
1308+
},
1309+
"MinvCpus": {
1310+
"Ref": "MinVCpuParameter"
1311+
},
1312+
"SecurityGroupIds": [
1313+
{
1314+
"Fn::GetAtt": [
1315+
"ParamertizedManagedCESecurityGroup772BD71B",
1316+
"GroupId"
1317+
]
1318+
}
1319+
],
1320+
"SpotIamFleetRole": {
1321+
"Fn::GetAtt": [
1322+
"SpotFleetRole6D4F7558",
1323+
"Arn"
1324+
]
1325+
},
1326+
"Subnets": [
1327+
{
1328+
"Ref": "vpcPrivateSubnet1Subnet934893E8"
1329+
},
1330+
{
1331+
"Ref": "vpcPrivateSubnet2Subnet7031C2BA"
1332+
}
1333+
],
1334+
"Type": "SPOT"
1335+
},
1336+
"ReplaceComputeEnvironment": false,
1337+
"State": "ENABLED",
1338+
"Type": "managed",
1339+
"UpdatePolicy": {}
1340+
}
12231341
}
12241342
},
12251343
"Parameters": {
12261344
"SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
12271345
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
12281346
"Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
12291347
},
1348+
"MinVCpuParameter": {
1349+
"Type": "Number",
1350+
"Default": 512,
1351+
"MinValue": 0
1352+
},
1353+
"MaxVCpuParameter": {
1354+
"Type": "Number",
1355+
"Default": 512,
1356+
"MinValue": 1
1357+
},
1358+
"SpotBidPercentageParameter": {
1359+
"Type": "Number",
1360+
"Default": 100,
1361+
"MinValue": 1
1362+
},
12301363
"BootstrapVersion": {
12311364
"Type": "AWS::SSM::Parameter::Value<String>",
12321365
"Default": "/cdk-bootstrap/hnb659fds/version",

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/manifest.json

+50-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)