Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { App, Stack } from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import { ManagedEc2EcsComputeEnvironment } from 'aws-cdk-lib/aws-batch';

const app = new App();
const stack = new Stack(app, 'batch-compute-environment-tags-stack');
const vpc = new ec2.Vpc(stack, 'vpc', { restrictDefaultSecurityGroup: false });

new ManagedEc2EcsComputeEnvironment(stack, 'TaggedComputeEnv', {
vpc,
tags: {
Environment: 'test',
Application: 'myapp',
},
});

new integ.IntegTest(app, 'BatchComputeEnvironmentTagsTest', {
testCases: [stack],
});

app.synth();
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/aws-batch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ const tagCE = new batch.ManagedEc2EcsComputeEnvironment(this, 'CEThatMakesTagged
Tags.of(tagCE).add('super', 'salamander');
```

Tags can be applied directly to the underlying ComputeEnvironment resource.:

```ts
declare const vpc: ec2.IVpc;

new batch.ManagedEc2EcsComputeEnvironment(this, 'myTaggedComputeEnv', {
vpc,
tags: {
Environment: 'production',
Application: 'my-app',
},
});
```

Unmanaged `ComputeEnvironment`s do not support `maxvCpus` or `minvCpus` because you must provision and manage the instances yourself;
that is, Batch will not scale them up and down as needed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,13 @@ export interface ManagedEc2EcsComputeEnvironmentProps extends ManagedComputeEnvi
* @default - no placement group
*/
readonly placementGroup?: ec2.IPlacementGroupRef;

/**
* Key-value pairs to associate with the compute environment.
*
* @default - no tags
*/
readonly tags?: { [key: string]: string };
}

/**
Expand Down Expand Up @@ -731,6 +738,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
const resource = new CfnComputeEnvironment(this, 'Resource', {
...baseManagedResourceProperties(this, subnetIds),
computeEnvironmentName: props.computeEnvironmentName,
tags: props.tags as any,
computeResources: {
...baseManagedResourceProperties(this, subnetIds).computeResources as CfnComputeEnvironment.ComputeResourcesProperty,
minvCpus: this.minvCpus,
Expand All @@ -752,7 +760,6 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
};
}),
placementGroup: props.placementGroup?.placementGroupRef.groupName,
tags: this.tags.renderedTags as any,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,35 @@ describe('ManagedEc2EksComputeEnvironment', () => {
});
});

describe('ManagedEc2EcsComputeEnvironment tags', () => {
let stack: Stack;
let vpc: ec2.Vpc;

beforeEach(() => {
stack = new Stack();
vpc = new ec2.Vpc(stack, 'vpc');
});

test('tags are rendered in CloudFormation', () => {
// WHEN
new ManagedEc2EcsComputeEnvironment(stack, 'MyCE', {
vpc,
tags: {
Environment: 'test',
Application: 'myapp',
},
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', {
Tags: {
Environment: 'test',
Application: 'myapp',
},
});
});
});

describe('FargateComputeEnvironment', () => {
beforeEach(() => {
stack = new Stack();
Expand Down
Loading