Skip to content
Merged
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
35 changes: 35 additions & 0 deletions packages/@aws-cdk/aws-batch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,38 @@
<!--END STABILITY BANNER-->

This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.

## Launch template support

### Usage
Simply define your Launch Template:
```typescript
const myLaunchTemplate = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', {
launchTemplateName: 'extra-storage-template',
launchTemplateData: {
blockDeviceMappings: [
{
deviceName: '/dev/xvdcz',
ebs: {
encrypted: true,
volumeSize: 100,
volumeType: 'gp2'
}
}
]
}
});
```
and use it:

```typescript
const myComputeEnv = new batch.ComputeEnvironment(this, 'ComputeEnv', {
computeResources: {
launchTemplate: {
launchTemplateName: myLaunchTemplate.launchTemplateName as string, //or simply use an existing template name
},
vpc,
},
computeEnvironmentName: 'MyStorageCapableComputeEnvironment',
});
```
26 changes: 26 additions & 0 deletions packages/@aws-cdk/aws-batch/lib/compute-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ export enum AllocationStrategy {
SPOT_CAPACITY_OPTIMIZED = 'SPOT_CAPACITY_OPTIMIZED',
}

/**
* Launch template property specification
*/
export interface LaunchTemplateSpecification {
/**
* The Launch template name
*/
readonly launchTemplateName: string;
/**
* The launch template version to be used (optional).
*
* @default - the default version of the launch template
*/
readonly version?: string;
}

/**
* Properties for defining the structure of the batch compute cluster.
*/
Expand Down Expand Up @@ -79,6 +95,15 @@ export interface ComputeResources {
*/
readonly instanceRole?: string;

/**
* An optional launch template to associate with your compute resources.
* For more information, see README file.
*
* @default - no custom launch template will be used
* @link https://docs.aws.amazon.com/batch/latest/userguide/launch-templates.html
*/
readonly launchTemplate?: LaunchTemplateSpecification;

/**
* The types of EC2 instances that may be launched in the compute environment. You can specify instance
* families to launch any instance type within those families (for example, c4 or p3), or you can specify
Expand Down Expand Up @@ -333,6 +358,7 @@ export class ComputeEnvironment extends Resource implements IComputeEnvironment
}).roleName]
}).attrArn,
instanceTypes: this.buildInstanceTypes(props.computeResources.instanceTypes),
launchTemplate: props.computeResources.launchTemplate,
maxvCpus: props.computeResources.maxvCpus || 256,
minvCpus: props.computeResources.minvCpus || 0,
securityGroupIds: this.buildSecurityGroupIds(props.computeResources.vpc, props.computeResources.securityGroups),
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-batch/test/integ.batch.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,24 @@
}
}
},
"ec2launchtemplate": {
"Type": "AWS::EC2::LaunchTemplate",
"Properties": {
"LaunchTemplateData": {
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xvdcz",
"Ebs": {
"Encrypted": true,
"VolumeSize": 100,
"VolumeType": "gp2"
}
}
]
},
"LaunchTemplateName": "EC2LaunchTemplate"
}
},
"batchunmanagedcomputeenvResourceServiceInstanceRoleCA40AF77": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -817,6 +835,9 @@
"InstanceTypes": [
"optimal"
],
"LaunchTemplate": {
"LaunchTemplateName": "EC2LaunchTemplate"
},
"MaxvCpus": 256,
"MinvCpus": 0,
"SecurityGroupIds": [
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-batch/test/integ.batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ const stack = new cdk.Stack(app, 'batch-stack');

const vpc = new ec2.Vpc(stack, 'vpc');

const launchTemplate = new ec2.CfnLaunchTemplate(stack, 'ec2-launch-template', {
launchTemplateName: 'EC2LaunchTemplate',
launchTemplateData: {
blockDeviceMappings: [
{
deviceName: '/dev/xvdcz',
ebs: {
encrypted: true,
volumeSize: 100,
volumeType: 'gp2'
}
}
]
}
});

new batch.JobQueue(stack, 'batch-job-queue', {
computeEnvironments: [
{
Expand All @@ -24,6 +40,9 @@ new batch.JobQueue(stack, 'batch-job-queue', {
computeResources: {
type: batch.ComputeResourceType.ON_DEMAND,
vpc,
launchTemplate: {
launchTemplateName: launchTemplate.launchTemplateName as string,
},
},
}),
order: 2,
Expand Down