-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(batch): add JobQueue, ComputeEnvironment and JobDefinition const…
…ructs
- Loading branch information
Showing
11 changed files
with
2,988 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
86
packages/@aws-cdk/aws-batch/lib/job-definition-image-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
})); | ||
} | ||
} |
Oops, something went wrong.