From f8113d58fa49866c79f9e2aafe2cc726e3af380f Mon Sep 17 00:00:00 2001 From: Brendan Doyle Date: Wed, 15 Jan 2025 11:21:01 -0800 Subject: [PATCH 1/4] fix aws-batch managed compute environment L2 property validations to allow CfnParameters --- .../lib/managed-compute-environment.ts | 18 ++- .../test/managed-compute-environment.test.ts | 130 +++++++++++++++++- 2 files changed, 140 insertions(+), 8 deletions(-) diff --git a/packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts b/packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts index c9f03e9f0dd73..5be72d72c0004 100644 --- a/packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts +++ b/packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts @@ -5,7 +5,7 @@ import * as ec2 from '../../aws-ec2'; import * as eks from '../../aws-eks'; import * as iam from '../../aws-iam'; import { IRole } from '../../aws-iam'; -import { ArnFormat, Duration, ITaggable, Lazy, Resource, Stack, TagManager, TagType } from '../../core'; +import { ArnFormat, Duration, ITaggable, Lazy, Resource, Stack, TagManager, TagType, Token } from '../../core'; /** * Represents a Managed ComputeEnvironment. Batch will provision EC2 Instances to @@ -1193,10 +1193,14 @@ function validateSpotConfig(id: string, spot?: boolean, spotBidPercentage?: numb if (spotBidPercentage) { if (!spot) { throw new Error(`Managed ComputeEnvironment '${id}' specifies 'spotBidPercentage' without specifying 'spot'`); - } else if (spotBidPercentage > 100) { - throw new Error(`Managed ComputeEnvironment '${id}' specifies 'spotBidPercentage' > 100`); - } else if (spotBidPercentage < 0) { - throw new Error(`Managed ComputeEnvironment '${id}' specifies 'spotBidPercentage' < 0`); + } + + if (!Token.isUnresolved(spotBidPercentage)) { + if (spotBidPercentage > 100) { + throw new Error(`Managed ComputeEnvironment '${id}' specifies 'spotBidPercentage' > 100`); + } else if (spotBidPercentage < 0) { + throw new Error(`Managed ComputeEnvironment '${id}' specifies 'spotBidPercentage' < 0`); + } } } @@ -1208,10 +1212,10 @@ function validateSpotConfig(id: string, spot?: boolean, spotBidPercentage?: numb } function validateVCpus(id: string, minvCpus: number, maxvCpus: number): void { - if (minvCpus < 0) { + if (!Token.isUnresolved(minvCpus) && minvCpus < 0) { throw new Error(`Managed ComputeEnvironment '${id}' has 'minvCpus' = ${minvCpus} < 0; 'minvCpus' cannot be less than zero`); } - if (minvCpus > maxvCpus) { + if (!Token.isUnresolved(minvCpus) && !Token.isUnresolved(maxvCpus) && minvCpus > maxvCpus) { throw new Error(`Managed ComputeEnvironment '${id}' has 'minvCpus' = ${minvCpus} > 'maxvCpus' = ${maxvCpus}; 'minvCpus' cannot be greater than 'maxvCpus'`); } } diff --git a/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts b/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts index 90a4a6fceb71d..c9495518bf848 100644 --- a/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts +++ b/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts @@ -3,8 +3,9 @@ import { Template } from '../../assertions'; import * as ec2 from '../../aws-ec2'; import * as eks from '../../aws-eks'; import { ArnPrincipal, Role, ServicePrincipal } from '../../aws-iam'; -import { Stack, Duration, Tags } from '../../core'; +import { Stack, Duration, Tags, CfnParameter } from '../../core'; import { AllocationStrategy, CfnComputeEnvironmentProps, ManagedEc2EcsComputeEnvironment, ManagedEc2EcsComputeEnvironmentProps, ManagedEc2EksComputeEnvironment, ManagedEc2EksComputeEnvironmentProps, FargateComputeEnvironment, EcsMachineImageType, EksMachineImageType } from '../lib'; +import { Type } from '@aws-sdk/client-cloudwatch-logs'; const defaultExpectedEcsProps: CfnComputeEnvironmentProps = { type: 'managed', @@ -133,6 +134,32 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] }); }); + test('can specify parameterized maxvCpus', () => { + // WHEN + const maxVCpuParameter = new CfnParameter(stack, 'MaxVCpuParameter', { + default: 512, + minValue: 1, + type: 'Number', + }); + + new ComputeEnvironment(stack, 'MyCE', { + ...defaultProps, + vpc, + maxvCpus: maxVCpuParameter.valueAsNumber, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', { + ...expectedProps, + ComputeResources: { + ...defaultComputeResources, + MaxvCpus: { + Ref: 'MaxVCpuParameter', + }, + }, + }); + }); + test('can specify minvCpus', () => { // WHEN new ComputeEnvironment(stack, 'MyCE', { @@ -151,6 +178,61 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] }); }); + test('can specify parameterized minvCpus', () => { + // WHEN + const minVCpuParameter = new CfnParameter(stack, 'MinVCpuParameter', { + default: 512, + minValue: 1, + type: 'Number', + }); + + new ComputeEnvironment(stack, 'MyCE', { + ...defaultProps, + vpc, + minvCpus: minVCpuParameter.valueAsNumber, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', { + ...expectedProps, + ComputeResources: { + ...defaultComputeResources, + MinvCpus: { + Ref: 'MinVCpuParameter', + }, + }, + }); + }); + + test('can specify spotBidPercentage as a parameter', () => { + // WHEN + const spotBidPercentageParameter = new CfnParameter(stack, 'SpotBidPercentageParameter', { + default: 100, + minValue: 1, + type: 'Number', + }); + + new ComputeEnvironment(stack, 'MyCE', { + ...defaultProps, + vpc, + spot: true, + spotBidPercentage: spotBidPercentageParameter.valueAsNumber, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', { + ...expectedProps, + ComputeResources: { + ...defaultComputeResources, + Type: 'SPOT', + AllocationStrategy: AllocationStrategy.SPOT_PRICE_CAPACITY_OPTIMIZED, + BidPercentage: { + Ref: 'SpotBidPercentageParameter', + }, + }, + }); + }); + test('can be disabled', () => { // WHEN new ComputeEnvironment(stack, 'MyCE', { @@ -675,6 +757,20 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] }).toThrow(/Managed ComputeEnvironment 'MyCE' specifies 'spotBidPercentage' without specifying 'spot'/); }); + test('throws error when spotBidPercentage is a parameter and spot is not enabled', () => { + // THEN + expect(() => { + new ComputeEnvironment(stack, 'MyCE', { + ...defaultProps, + vpc, + spotBidPercentage: new CfnParameter(stack, 'SpotBidPercentageParameter', { + type: 'Number', + }), + spot: false, + }); + }).toThrow(/Managed ComputeEnvironment 'MyCE' specifies 'spotBidPercentage' without specifying 'spot'/); + }); + test('throws error when spotBidPercentage > 100', () => { // THEN expect(() => { @@ -711,6 +807,38 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] }).toThrow(/Managed ComputeEnvironment 'MyCE' has 'minvCpus' = 1024 > 'maxvCpus' = 512; 'minvCpus' cannot be greater than 'maxvCpus'/); }); + test('skips validation for minvCpus < maxvCpus check when either properties are tokens', () => { + // WHEN + const minVCpuParameter = new CfnParameter(stack, 'MinVCpuParameter', { + default: 512, + minValue: 0, + type: 'Number', + }); + + const maxVCpuParameter = new CfnParameter(stack, 'MaxVCpuParameter', { + default: 512, + minValue: 1, + type: 'Number', + }); + + // THEN + expect(() => { + new ComputeEnvironment(stack, 'MyCE', { + ...defaultProps, + vpc, + maxvCpus: maxVCpuParameter.valueAsNumber, + minvCpus: 1024, + }); + + new ComputeEnvironment(stack, 'MyOtherCE', { + ...defaultProps, + vpc, + maxvCpus: 1024, + minvCpus: minVCpuParameter.valueAsNumber, + }); + }).not.toThrow(/Managed ComputeEnvironment 'MyCE' has 'minvCpus' = 1024 > 'maxvCpus' = 512; 'minvCpus' cannot be greater than 'maxvCpus'/); + }); + test('throws error when minvCpus < 0', () => { // THEN expect(() => { From 5d34b786813478e3a291c1229019d9ccdb12ebb8 Mon Sep 17 00:00:00 2001 From: Brendan Doyle Date: Wed, 15 Jan 2025 11:53:26 -0800 Subject: [PATCH 2/4] add integration test --- .../test/integ.managed-compute-environment.ts | 27 ++++++++++++++++++- .../test/managed-compute-environment.test.ts | 1 - 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts index 0d71b9cfbff4e..79679e0128bb9 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts @@ -1,7 +1,7 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2'; import { LaunchTemplate } from 'aws-cdk-lib/aws-ec2'; import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -import { App, Duration, Stack, Tags } from 'aws-cdk-lib'; +import { App, CfnParameter, Duration, Stack, Tags } from 'aws-cdk-lib'; import * as integ from '@aws-cdk/integ-tests-alpha'; import { AllocationStrategy, FargateComputeEnvironment, ManagedEc2EcsComputeEnvironment, EcsMachineImageType } from 'aws-cdk-lib/aws-batch'; @@ -86,6 +86,31 @@ new ManagedEc2EcsComputeEnvironment(stack, 'ECS_AL2023', { }], }); +new ManagedEc2EcsComputeEnvironment(stack, 'ParamertizedManagedCE', { + vpc, + images: [{ + image: new ec2.AmazonLinuxImage(), + }], + minvCpus: new CfnParameter(stack, 'MinVCpuParameter', { + default: 512, + minValue: 0, + type: 'Number' + }).valueAsNumber, + maxvCpus: new CfnParameter(stack, 'MaxVCpuParameter', { + default: 512, + minValue: 1, + }).valueAsNumber, + spot: true, + spotBidPercentage: new CfnParameter(stack, 'SpotBidPercentageParameter', { + default: 100, + minValue: 1, + type: 'Number', + }).valueAsNumber, + spotFleetRole: new Role(stack, 'SpotFleetRole', { + assumedBy: new ServicePrincipal('batch.amazonaws.com'), + }), +}); + new integ.IntegTest(app, 'BatchManagedComputeEnvironmentTest', { testCases: [stack], }); diff --git a/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts b/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts index c9495518bf848..5f0756f3cd691 100644 --- a/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts +++ b/packages/aws-cdk-lib/aws-batch/test/managed-compute-environment.test.ts @@ -5,7 +5,6 @@ import * as eks from '../../aws-eks'; import { ArnPrincipal, Role, ServicePrincipal } from '../../aws-iam'; import { Stack, Duration, Tags, CfnParameter } from '../../core'; import { AllocationStrategy, CfnComputeEnvironmentProps, ManagedEc2EcsComputeEnvironment, ManagedEc2EcsComputeEnvironmentProps, ManagedEc2EksComputeEnvironment, ManagedEc2EksComputeEnvironmentProps, FargateComputeEnvironment, EcsMachineImageType, EksMachineImageType } from '../lib'; -import { Type } from '@aws-sdk/client-cloudwatch-logs'; const defaultExpectedEcsProps: CfnComputeEnvironmentProps = { type: 'managed', From a118489bf9369ebcff029b104862e1975b6a6f3c Mon Sep 17 00:00:00 2001 From: Brendan Doyle Date: Wed, 15 Jan 2025 13:30:57 -0800 Subject: [PATCH 3/4] fix integration test --- .../test/integ.managed-compute-environment.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts index 79679e0128bb9..546dc3fbbb613 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.ts @@ -9,6 +9,10 @@ const app = new App(); const stack = new Stack(app, 'batch-stack'); const vpc = new ec2.Vpc(stack, 'vpc', { restrictDefaultSecurityGroup: false }); +const spotFleetRole = new Role(stack, 'SpotFleetRole', { + assumedBy: new ServicePrincipal('batch.amazonaws.com'), +}); + new FargateComputeEnvironment(stack, 'minimalPropsFargate', { vpc, maxvCpus: 512, @@ -54,9 +58,7 @@ new ManagedEc2EcsComputeEnvironment(stack, 'SpotEc2', { }], spot: true, spotBidPercentage: 95, - spotFleetRole: new Role(stack, 'SpotFleetRole', { - assumedBy: new ServicePrincipal('batch.amazonaws.com'), - }), + spotFleetRole: spotFleetRole, }); new ManagedEc2EcsComputeEnvironment(stack, 'AllocationStrategySPOT_CAPACITY', { @@ -94,11 +96,12 @@ new ManagedEc2EcsComputeEnvironment(stack, 'ParamertizedManagedCE', { minvCpus: new CfnParameter(stack, 'MinVCpuParameter', { default: 512, minValue: 0, - type: 'Number' + type: 'Number', }).valueAsNumber, maxvCpus: new CfnParameter(stack, 'MaxVCpuParameter', { default: 512, minValue: 1, + type: 'Number', }).valueAsNumber, spot: true, spotBidPercentage: new CfnParameter(stack, 'SpotBidPercentageParameter', { @@ -106,9 +109,7 @@ new ManagedEc2EcsComputeEnvironment(stack, 'ParamertizedManagedCE', { minValue: 1, type: 'Number', }).valueAsNumber, - spotFleetRole: new Role(stack, 'SpotFleetRole', { - assumedBy: new ServicePrincipal('batch.amazonaws.com'), - }), + spotFleetRole: spotFleetRole, }); new integ.IntegTest(app, 'BatchManagedComputeEnvironmentTest', { From fb0ab58518ff2a8deb6fd38d60500faefefb6877 Mon Sep 17 00:00:00 2001 From: Brendan Doyle Date: Wed, 15 Jan 2025 14:13:25 -0800 Subject: [PATCH 4/4] integration snapshot --- ...efaultTestDeployAssertD4528F80.assets.json | 2 +- .../batch-stack.assets.json | 6 +- .../batch-stack.template.json | 167 +++++++++- .../cdk.out | 2 +- .../integ.json | 2 +- .../manifest.json | 58 +++- .../tree.json | 302 +++++++++++++++--- 7 files changed, 463 insertions(+), 76 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/BatchManagedComputeEnvironmentTestDefaultTestDeployAssertD4528F80.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/BatchManagedComputeEnvironmentTestDefaultTestDeployAssertD4528F80.assets.json index de953f1e34aad..70f739de9114f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/BatchManagedComputeEnvironmentTestDefaultTestDeployAssertD4528F80.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/BatchManagedComputeEnvironmentTestDefaultTestDeployAssertD4528F80.assets.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "39.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json index 7fbccde788f96..0690efcf19363 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json @@ -1,7 +1,7 @@ { - "version": "36.0.0", + "version": "39.0.0", "files": { - "29532266ce5c96c372f99765edc76d90da88dd7316798a6e86946bc0ffa1802d": { + "a7f441ca77fafeef4eec69135aa635b2c503f8c144801e46f8b4423ce75b69c3": { "source": { "path": "batch-stack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "29532266ce5c96c372f99765edc76d90da88dd7316798a6e86946bc0ffa1802d.json", + "objectKey": "a7f441ca77fafeef4eec69135aa635b2c503f8c144801e46f8b4423ce75b69c3.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json index c99047b447f4b..0df7fad833d9c 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json @@ -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": { @@ -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": { @@ -1220,6 +1220,124 @@ "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": { @@ -1227,6 +1345,21 @@ "Type": "AWS::SSM::Parameter::Value", "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", "Default": "/cdk-bootstrap/hnb659fds/version", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/cdk.out index 1f0068d32659a..91e1a8b9901d5 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"36.0.0"} \ No newline at end of file +{"version":"39.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/integ.json index 1d97ef0a4308e..e0db1b12da945 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "39.0.0", "testCases": { "BatchManagedComputeEnvironmentTest/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/manifest.json index 9ec827b896504..1f277a0c919ca 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "39.0.0", "artifacts": { "batch-stack.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/29532266ce5c96c372f99765edc76d90da88dd7316798a6e86946bc0ffa1802d.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/a7f441ca77fafeef4eec69135aa635b2c503f8c144801e46f8b4423ce75b69c3.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -172,6 +172,12 @@ "data": "vpcVPCGW7984C166" } ], + "/batch-stack/SpotFleetRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "SpotFleetRole6D4F7558" + } + ], "/batch-stack/minimalPropsFargate/SecurityGroup/Resource": [ { "type": "aws:cdk:logicalId", @@ -262,12 +268,6 @@ "data": "LaunchTemplate04EC5460" } ], - "/batch-stack/SpotFleetRole/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "SpotFleetRole6D4F7558" - } - ], "/batch-stack/SpotEc2/SecurityGroup/Resource": [ { "type": "aws:cdk:logicalId", @@ -364,6 +364,48 @@ "data": "ECSAL20239DA0188B" } ], + "/batch-stack/MinVCpuParameter": [ + { + "type": "aws:cdk:logicalId", + "data": "MinVCpuParameter" + } + ], + "/batch-stack/MaxVCpuParameter": [ + { + "type": "aws:cdk:logicalId", + "data": "MaxVCpuParameter" + } + ], + "/batch-stack/SpotBidPercentageParameter": [ + { + "type": "aws:cdk:logicalId", + "data": "SpotBidPercentageParameter" + } + ], + "/batch-stack/ParamertizedManagedCE/SecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ParamertizedManagedCESecurityGroup772BD71B" + } + ], + "/batch-stack/ParamertizedManagedCE/InstanceProfileRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ParamertizedManagedCEInstanceProfileRoleB54B7F8B" + } + ], + "/batch-stack/ParamertizedManagedCE/InstanceProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "ParamertizedManagedCEInstanceProfileDF9CB175" + } + ], + "/batch-stack/ParamertizedManagedCE/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ParamertizedManagedCE07932AA8" + } + ], "/batch-stack/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/tree.json index 7d665f06bcdc1..bd5737016e40d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.managed-compute-environment.js.snapshot/tree.json @@ -651,6 +651,49 @@ "version": "0.0.0" } }, + "SpotFleetRole": { + "id": "SpotFleetRole", + "path": "batch-stack/SpotFleetRole", + "children": { + "ImportSpotFleetRole": { + "id": "ImportSpotFleetRole", + "path": "batch-stack/SpotFleetRole/ImportSpotFleetRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "batch-stack/SpotFleetRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "batch.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, "minimalPropsFargate": { "id": "minimalPropsFargate", "path": "batch-stack/minimalPropsFargate", @@ -1276,49 +1319,6 @@ "version": "0.0.0" } }, - "SpotFleetRole": { - "id": "SpotFleetRole", - "path": "batch-stack/SpotFleetRole", - "children": { - "ImportSpotFleetRole": { - "id": "ImportSpotFleetRole", - "path": "batch-stack/SpotFleetRole/ImportSpotFleetRole", - "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" - } - }, - "Resource": { - "id": "Resource", - "path": "batch-stack/SpotFleetRole/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::IAM::Role", - "aws:cdk:cloudformation:props": { - "assumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "batch.amazonaws.com" - } - } - ], - "Version": "2012-10-17" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" - } - }, "SpotEc2": { "id": "SpotEc2", "path": "batch-stack/SpotEc2", @@ -2052,6 +2052,218 @@ "version": "0.0.0" } }, + "MinVCpuParameter": { + "id": "MinVCpuParameter", + "path": "batch-stack/MinVCpuParameter", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "MaxVCpuParameter": { + "id": "MaxVCpuParameter", + "path": "batch-stack/MaxVCpuParameter", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "SpotBidPercentageParameter": { + "id": "SpotBidPercentageParameter", + "path": "batch-stack/SpotBidPercentageParameter", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "ParamertizedManagedCE": { + "id": "ParamertizedManagedCE", + "path": "batch-stack/ParamertizedManagedCE", + "children": { + "SecurityGroup": { + "id": "SecurityGroup", + "path": "batch-stack/ParamertizedManagedCE/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "batch-stack/ParamertizedManagedCE/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "batch-stack/ParamertizedManagedCE/SecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "vpcId": { + "Ref": "vpcA2121C38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" + } + }, + "InstanceProfileRole": { + "id": "InstanceProfileRole", + "path": "batch-stack/ParamertizedManagedCE/InstanceProfileRole", + "children": { + "ImportInstanceProfileRole": { + "id": "ImportInstanceProfileRole", + "path": "batch-stack/ParamertizedManagedCE/InstanceProfileRole/ImportInstanceProfileRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "batch-stack/ParamertizedManagedCE/InstanceProfileRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "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" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "InstanceProfile": { + "id": "InstanceProfile", + "path": "batch-stack/ParamertizedManagedCE/InstanceProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", + "aws:cdk:cloudformation:props": { + "roles": [ + { + "Ref": "ParamertizedManagedCEInstanceProfileRoleB54B7F8B" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "batch-stack/ParamertizedManagedCE/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Batch::ComputeEnvironment", + "aws:cdk:cloudformation:props": { + "computeResources": { + "maxvCpus": { + "Ref": "MaxVCpuParameter" + }, + "type": "SPOT", + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "ParamertizedManagedCESecurityGroup772BD71B", + "GroupId" + ] + } + ], + "subnets": [ + { + "Ref": "vpcPrivateSubnet1Subnet934893E8" + }, + { + "Ref": "vpcPrivateSubnet2Subnet7031C2BA" + } + ], + "minvCpus": { + "Ref": "MinVCpuParameter" + }, + "instanceRole": { + "Fn::GetAtt": [ + "ParamertizedManagedCEInstanceProfileDF9CB175", + "Arn" + ] + }, + "instanceTypes": [ + "optimal" + ], + "spotIamFleetRole": { + "Fn::GetAtt": [ + "SpotFleetRole6D4F7558", + "Arn" + ] + }, + "allocationStrategy": "SPOT_PRICE_CAPACITY_OPTIMIZED", + "bidPercentage": { + "Ref": "SpotBidPercentageParameter" + }, + "ec2Configuration": [ + { + "imageIdOverride": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "imageType": "ECS_AL2" + } + ] + }, + "replaceComputeEnvironment": false, + "state": "ENABLED", + "type": "managed", + "updatePolicy": {} + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_batch.CfnComputeEnvironment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_batch.ManagedEc2EcsComputeEnvironment", + "version": "0.0.0" + } + }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "batch-stack/BootstrapVersion", @@ -2087,7 +2299,7 @@ "path": "BatchManagedComputeEnvironmentTest/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.3.0" + "version": "10.4.2" } }, "DeployAssert": { @@ -2133,7 +2345,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.3.0" + "version": "10.4.2" } } },