Skip to content

Commit

Permalink
feat(batch): add JobQueue, ComputeEnvironment and JobDefinition const…
Browse files Browse the repository at this point in the history
…ructs
  • Loading branch information
stephnr authored Feb 24, 2020
1 parent ab9b77c commit c8a22b1
Show file tree
Hide file tree
Showing 11 changed files with 2,988 additions and 4 deletions.
458 changes: 458 additions & 0 deletions packages/@aws-cdk/aws-batch/lib/compute-environment.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-batch/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// AWS::Batch CloudFormation Resources:
export * from './batch.generated';
export * from './compute-environment';
export * from './job-definition';
export * from './job-queue';
86 changes: 86 additions & 0 deletions packages/@aws-cdk/aws-batch/lib/job-definition-image-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as ecs from '@aws-cdk/aws-ecs';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { JobDefinitionContainer } from './job-definition';

/**
* TaskDefinitionRole
*
* Defines the required properties of a Batch Job Definition.
*/
interface TaskDefinitionProps {
/**
* Defines the IAM role used when executing this task definition
*/
readonly executionRole: iam.IRole;
}

/**
* Batch Job Task Definition
*
* Defines a Batch Job Task Definition. The properties of this task definition mirrors
* those of an {@link ecs.ContainerDefinition}. This class is a wrapper on that structure.
*/
class TaskDefinition {
/**
* The IAM role used during execution of the task definition. This IAM role should
* contain the relevant access required to interact with resources your application needs to perform.
*/
public readonly executionRole: iam.IRole;

constructor(props: TaskDefinitionProps) {
this.executionRole = props.executionRole;
}

/**
* Internal function to allow the Batch Job task defintion
* to match the CDK requirements of an EC2 task definition.
*
* @internal
*/
// tslint:disable-next-line: no-empty
public _linkContainer() {}

/**
* Retrieves the execution role for this task definition
*/
public obtainExecutionRole(): iam.IRole {
return this.executionRole;
}
}

/**
* The configuration for creating a batch container image.
*/
export class JobDefinitionImageConfig {
/**
* Specifies the name of the container image
*/
public readonly imageName: string;

constructor(scope: cdk.Construct, container: JobDefinitionContainer) {
const config = this.bindImageConfig(scope, container);

this.imageName = config.imageName;
}

private bindImageConfig(scope: cdk.Construct, container: JobDefinitionContainer): ecs.ContainerImageConfig {
return container.image.bind(scope, new ecs.ContainerDefinition(scope, 'Resource-Batch-Job-Container-Definition', {
command: container.command,
cpu: container.vcpus,
image: container.image,
environment: container.environment,
linuxParameters: container.linuxParams,
memoryLimitMiB: container.memoryLimitMiB,
privileged: container.privileged,
readonlyRootFilesystem: container.readOnly,
gpuCount: container.gpuCount,
user: container.user,
taskDefinition: new TaskDefinition({
executionRole: container.jobRole || new iam.LazyRole(scope, 'Resource-Batch-Task-Definition-Role', {
assumedBy: new iam.ServicePrincipal('batch.amazonaws.com')
}),
}) as unknown as ecs.TaskDefinition,
}));
}
}
Loading

0 comments on commit c8a22b1

Please sign in to comment.