agent-claw: automated task changes

This commit is contained in:
daniel
2026-05-06 18:55:16 -05:00
parent 38905bb1e9
commit 732b00fb66
8494 changed files with 2018127 additions and 4 deletions

13
cdk/node_modules/aws-cdk-lib/aws-batch/.jsiirc.json generated vendored Normal file
View File

@@ -0,0 +1,13 @@
{
"targets": {
"java": {
"package": "software.amazon.awscdk.services.batch"
},
"dotnet": {
"namespace": "Amazon.CDK.AWS.Batch"
},
"python": {
"module": "aws_cdk.aws_batch"
}
}
}

820
cdk/node_modules/aws-cdk-lib/aws-batch/README.md generated vendored Normal file
View File

@@ -0,0 +1,820 @@
# AWS Batch Construct Library
This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.
AWS Batch is a batch processing tool for efficiently running hundreds of thousands computing jobs in AWS.
Batch can dynamically provision [Amazon EC2](https://aws.amazon.com/ec2/) Instances to meet the resource requirements of submitted jobs
and simplifies the planning, scheduling, and executions of your batch workloads. Batch achieves this through four different resources:
* ComputeEnvironments: Contain the resources used to execute Jobs
* JobDefinitions: Define a type of Job that can be submitted
* JobQueues: Route waiting Jobs to ComputeEnvironments
* SchedulingPolicies: Applied to Queues to control how and when Jobs exit the JobQueue and enter the ComputeEnvironment
`ComputeEnvironment`s can be managed or unmanaged. Batch will automatically provision EC2 Instances in a managed `ComputeEnvironment` and will
not provision any Instances in an unmanaged `ComputeEnvironment`. Managed `ComputeEnvironment`s can use ECS, Fargate, or EKS resources to spin up
EC2 Instances in (ensure your EKS Cluster has [been configured](https://docs.aws.amazon.com/batch/latest/userguide/getting-started-eks.html)
to support a Batch ComputeEnvironment before linking it). You can use Launch Templates and Placement Groups to configure exactly how these resources
will be provisioned.
`JobDefinition`s can use either ECS resources or EKS resources. ECS `JobDefinition`s can use multiple containers to execute distributed workloads.
EKS `JobDefinition`s can only execute a single container. Submitted Jobs use `JobDefinition`s as templates.
`JobQueue`s must link at least one `ComputeEnvironment`. Jobs exit the Queue in FIFO order unless a `SchedulingPolicy` is specified.
`SchedulingPolicy`s tell the Scheduler how to choose which Jobs should be executed next by the ComputeEnvironment.
## Use Cases & Examples
### Cost Optimization
#### Spot Instances
Spot instances are significantly discounted EC2 instances that can be reclaimed at any time by AWS.
Workloads that are fault-tolerant or stateless can take advantage of spot pricing.
To use spot spot instances, set `spot` to `true` on a managed Ec2 or Fargate Compute Environment:
```ts
const vpc = new ec2.Vpc(this, 'VPC');
new batch.FargateComputeEnvironment(this, 'myFargateComputeEnv', {
vpc,
spot: true,
});
```
Batch allows you to specify the percentage of the on-demand instance that the current spot price
must be to provision the instance using the `spotBidPercentage`.
This defaults to 100%, which is the recommended value.
This value cannot be specified for `FargateComputeEnvironment`s
and only applies to `ManagedEc2EcsComputeEnvironment`s.
The following code configures a Compute Environment to only use spot instances that
are at most 20% the price of the on-demand instance price:
_Note_: For `FargateComputeEnvironment`, while the `FargateComputeEnvironmentProps` interface includes properties like `replaceComputeEnvironment`, `terminateOnUpdate`, `updateTimeout`, and `updateToLatestImageVersion`, these specific properties are **not applicable** when configuring AWS Batch Fargate compute environments. They primarily apply to EC2-based compute environments. Please refer to the official [AWS Batch UpdateComputeEnvironment API documentation](https://docs.aws.amazon.com/batch/latest/APIReference/API_UpdateComputeEnvironment.html) and [User Guide](https://docs.aws.amazon.com/batch/latest/userguide/updating-compute-environments.html) for details on updating Fargate compute environments.
```ts
const vpc = new ec2.Vpc(this, 'VPC');
new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
vpc,
spot: true,
spotBidPercentage: 20,
});
```
For stateful or otherwise non-interruption-tolerant workflows, omit `spot` or set it to `false` to only provision on-demand instances.
#### Choosing Your Instance Types
There are several ways to configure instance types for your compute environment:
##### Using Default Instance Classes (Recommended)
AWS Batch provides default instance classes that automatically select cost-effective, up-to-date instances based on your region.
This is the recommended approach for new projects:
```ts
const vpc = new ec2.Vpc(this, 'Vpc');
// Use ARM64 instances (e.g., m6g, c6g, r6g, c7g families)
new batch.ManagedEc2EcsComputeEnvironment(this, 'Arm64Ec2ComputeEnv', {
vpc,
defaultInstanceClasses: [batch.DefaultInstanceClass.ARM64],
});
// Use x86_64 instances (e.g., m6i, c6i, r6i, c7i families)
new batch.ManagedEc2EcsComputeEnvironment(this, 'X86_64Ec2ComputeEnv', {
vpc,
defaultInstanceClasses: [batch.DefaultInstanceClass.X86_64],
});
```
The `default_x86_64` and `default_arm64` categories are dynamically updated by AWS as new instance families become available in your region.
##### Using Specific Instance Types Only
To use only specific instance types without any automatic defaults, set `useOptimalInstanceClasses: false`:
```ts
const vpc = new ec2.Vpc(this, 'Vpc');
// Use only R4 instance class (Batch chooses the size)
new batch.ManagedEc2EcsComputeEnvironment(this, 'R4Ec2ComputeEnv', {
vpc,
useOptimalInstanceClasses: false,
instanceClasses: [ec2.InstanceClass.R4],
});
// Use only a specific instance type
new batch.ManagedEc2EcsComputeEnvironment(this, 'M5AdLargeEc2ComputeEnv', {
vpc,
useOptimalInstanceClasses: false,
instanceTypes: [ec2.InstanceType.of(ec2.InstanceClass.M5AD, ec2.InstanceSize.LARGE)],
});
```
##### Using Optimal Instance Classes
By default, `useOptimalInstanceClasses` is `true`, which adds the `optimal` instance type.
**Note**: Since November 2025, `optimal` behaves the same as `default_x86_64` and is dynamically updated as AWS introduces new instance families. Both options automatically select cost-effective x86_64 instance types (from the m6i, c6i, r6i, and c7i families) based on your region.
You can combine this with additional instance types:
```ts
declare const vpc: ec2.IVpc;
const computeEnv = new batch.ManagedEc2EcsComputeEnvironment(this, 'Ec2ComputeEnv', {
vpc,
instanceTypes: [ec2.InstanceType.of(ec2.InstanceClass.M5AD, ec2.InstanceSize.LARGE)],
// useOptimalInstanceClasses: true (default)
});
// Result: ['m5ad.large', 'optimal']
```
##### Instance Type Configuration Reference
| Goal | Configuration |
|------|---------------|
| Use latest x86_64 instances | `defaultInstanceClasses: [DefaultInstanceClass.X86_64]` or no configuration (default) |
| Use latest ARM64 instances | `defaultInstanceClasses: [DefaultInstanceClass.ARM64]` |
| Use only specific instance classes | `useOptimalInstanceClasses: false` + `instanceClasses: [...]` |
| Use only specific instance types | `useOptimalInstanceClasses: false` + `instanceTypes: [...]` |
| Use optimal + additional instances | `instanceClasses: [...]` or `instanceTypes: [...]` |
**Note**: Batch does not allow specifying instance types or classes with different architectures.
For example, `InstanceClass.A1` (ARM) cannot be specified alongside `optimal` (x86_64).
When using ARM-based instances (e.g., Graviton), use `defaultInstanceClasses: [DefaultInstanceClass.ARM64]`, or set `useOptimalInstanceClasses: false` and explicitly specify ARM instance classes/types.
**Note**: `useOptimalInstanceClasses` and `defaultInstanceClasses` cannot be used together.
#### Configure AMIs
You can configure Amazon Machine Images (AMIs). This example configures your `ComputeEnvironment` to use Amazon Linux 2023.
```ts
declare const vpc: ec2.IVpc;
new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
vpc,
images: [
{
imageType: batch.EcsMachineImageType.ECS_AL2023,
},
],
});
```
If your image needs GPU resources, specify `ECS_AL2023_NVIDIA`:
```ts
declare const vpc: ec2.IVpc;
new batch.ManagedEc2EcsComputeEnvironment(this, 'myGpuComputeEnv', {
vpc,
images: [
{
imageType: batch.EcsMachineImageType.ECS_AL2023_NVIDIA,
},
],
});
```
#### Allocation Strategies
| Allocation Strategy | Optimized for | Downsides |
| ----------------------- | ------------- | ----------------------------- |
| BEST_FIT | Cost | May limit throughput |
| BEST_FIT_PROGRESSIVE | Throughput | May increase cost |
| SPOT_CAPACITY_OPTIMIZED | Least interruption | Only useful on Spot instances |
| SPOT_PRICE_CAPACITY_OPTIMIZED | Least interruption + Price | Only useful on Spot instances |
Batch provides different Allocation Strategies to help it choose which instances to provision.
If your workflow tolerates interruptions, you should enable `spot` on your `ComputeEnvironment`
and use `SPOT_PRICE_CAPACITY_OPTIMIZED` (this is the default if `spot` is enabled).
This will tell Batch to choose the instance types from the ones youve specified that have
the most spot capacity available to minimize the chance of interruption and have the lowest price.
To get the most benefit from your spot instances,
you should allow Batch to choose from as many different instance types as possible.
If you only care about minimal interruptions and not want Batch to optimize for cost, use
`SPOT_CAPACITY_OPTIMIZED`. `SPOT_PRICE_CAPACITY_OPTIMIZED` is recommended over `SPOT_CAPACITY_OPTIMIZED`
for most use cases.
If your workflow does not tolerate interruptions and you want to minimize your costs at the expense
of potentially longer waiting times, use `AllocationStrategy.BEST_FIT`.
This will choose the lowest-cost instance type that fits all the jobs in the queue.
If instances of that type are not available,
the queue will not choose a new type; instead, it will wait for the instance to become available.
This can stall your `Queue`, with your compute environment only using part of its max capacity
(or none at all) until the `BEST_FIT` instance becomes available.
If you are running a workflow that does not tolerate interruptions and you want to maximize throughput,
you can use `AllocationStrategy.BEST_FIT_PROGRESSIVE`.
This is the default Allocation Strategy if `spot` is `false` or unspecified.
This strategy will examine the Jobs in the queue and choose whichever instance type meets the requirements
of the jobs in the queue and with the lowest cost per vCPU, just as `BEST_FIT`.
However, if not all of the capacity can be filled with this instance type,
it will choose a new next-best instance type to run any jobs that couldnt fit into the `BEST_FIT` capacity.
To make the most use of this allocation strategy,
it is recommended to use as many instance classes as is feasible for your workload.
This example shows a `ComputeEnvironment` that uses `BEST_FIT_PROGRESSIVE`
with `'optimal'` and `InstanceClass.M5` instance types:
```ts
declare const vpc: ec2.IVpc;
const computeEnv = new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
vpc,
instanceClasses: [ec2.InstanceClass.M5],
});
```
This example shows a `ComputeEnvironment` that uses `BEST_FIT` with `'optimal'` instances:
```ts
declare const vpc: ec2.IVpc;
const computeEnv = new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
vpc,
allocationStrategy: batch.AllocationStrategy.BEST_FIT,
});
```
*Note*: `allocationStrategy` cannot be specified on Fargate Compute Environments.
### Controlling vCPU allocation
You can specify the maximum and minimum vCPUs a managed `ComputeEnvironment` can have at any given time.
Batch will *always* maintain `minvCpus` worth of instances in your ComputeEnvironment, even if it is not executing any jobs,
and even if it is disabled. Batch will scale the instances up to `maxvCpus` worth of instances as
jobs exit the JobQueue and enter the ComputeEnvironment. If you use `AllocationStrategy.BEST_FIT_PROGRESSIVE`,
`AllocationStrategy.SPOT_PRICE_CAPACITY_OPTIMIZED`, or `AllocationStrategy.SPOT_CAPACITY_OPTIMIZED`,
batch may exceed `maxvCpus`; it will never exceed `maxvCpus` by more than a single instance type. This example configures a
`minvCpus` of 10 and a `maxvCpus` of 100:
```ts
declare const vpc: ec2.IVpc;
new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
vpc,
instanceClasses: [ec2.InstanceClass.R4],
minvCpus: 10,
maxvCpus: 100,
});
```
### Tagging Instances
You can tag any instances launched by your managed EC2 ComputeEnvironments by using the CDK `Tags` API:
```ts
declare const vpc: ec2.IVpc;
const tagCE = new batch.ManagedEc2EcsComputeEnvironment(this, 'CEThatMakesTaggedInstnaces', {
vpc,
});
Tags.of(tagCE).add('super', 'salamander');
```
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.
### Sharing a ComputeEnvironment between multiple JobQueues
Multiple `JobQueue`s can share the same `ComputeEnvironment`.
If multiple Queues are attempting to submit Jobs to the same `ComputeEnvironment`,
Batch will pick the Job from the Queue with the highest priority.
This example creates two `JobQueue`s that share a `ComputeEnvironment`:
```ts
declare const vpc: ec2.IVpc;
const sharedComputeEnv = new batch.FargateComputeEnvironment(this, 'spotEnv', {
vpc,
spot: true,
});
const lowPriorityQueue = new batch.JobQueue(this, 'JobQueue', {
priority: 1,
});
const highPriorityQueue = new batch.JobQueue(this, 'JobQueue', {
priority: 10,
});
lowPriorityQueue.addComputeEnvironment(sharedComputeEnv, 1);
highPriorityQueue.addComputeEnvironment(sharedComputeEnv, 1);
```
### React to jobs stuck in RUNNABLE state
You can react to jobs stuck in RUNNABLE state by setting a `jobStateTimeLimitActions` in `JobQueue`.
Specifies actions that AWS Batch will take after the job has remained at the head of the queue in the
specified state for longer than the specified time.
```ts
new batch.JobQueue(this, 'JobQueue', {
jobStateTimeLimitActions: [
{
action: batch.JobStateTimeLimitActionsAction.CANCEL,
maxTime: cdk.Duration.minutes(10),
reason: batch.JobStateTimeLimitActionsReason.INSUFFICIENT_INSTANCE_CAPACITY,
state: batch.JobStateTimeLimitActionsState.RUNNABLE,
},
]
});
```
### Fairshare Scheduling
Batch `JobQueue`s execute Jobs submitted to them in FIFO order unless you specify a `SchedulingPolicy`.
FIFO queuing can cause short-running jobs to be starved while long-running jobs fill the compute environment.
To solve this, Jobs can be associated with a share.
Shares consist of a `shareIdentifier` and a `weightFactor`, which is inversely correlated with the vCPU allocated to that share identifier.
When submitting a Job, you can specify its `shareIdentifier` to associate that particular job with that share.
Let's see how the scheduler uses this information to schedule jobs.
For example, if there are two shares defined as follows:
| Share Identifier | Weight Factor |
| ---------------- | ------------- |
| A | 1 |
| B | 1 |
The weight factors share the following relationship:
```math
A_{vCpus} / A_{Weight} = B_{vCpus} / B_{Weight}
```
where `BvCpus` is the number of vCPUs allocated to jobs with share identifier `'B'`, and `B_weight` is the weight factor of `B`.
The total number of vCpus allocated to a share is equal to the amount of jobs in that share times the number of vCpus necessary for every job.
Let's say that each A job needs 32 VCpus (`A_requirement` = 32) and each B job needs 64 vCpus (`B_requirement` = 64):
```math
A_{vCpus} = A_{Jobs} * A_{Requirement}
```
```math
B_{vCpus} = B_{Jobs} * B_{Requirement}
```
We have:
```math
A_{vCpus} / A_{Weight} = B_{vCpus} / B_{Weight}
```
```math
A_{Jobs} * A_{Requirement} / A_{Weight} = B_{Jobs} * B_{Requirement} / B_{Weight}
```
```math
A_{Jobs} * 32 / 1 = B_{Jobs} * 64 / 1
```
```math
A_{Jobs} * 32 = B_{Jobs} * 64
```
```math
A_{Jobs} = B_{Jobs} * 2
```
Thus the scheduler will schedule two `'A'` jobs for each `'B'` job.
You can control the weight factors to change these ratios, but note that
weight factors are inversely correlated with the vCpus allocated to the corresponding share.
This example would be configured like this:
```ts
const fairsharePolicy = new batch.FairshareSchedulingPolicy(this, 'myFairsharePolicy');
fairsharePolicy.addShare({
shareIdentifier: 'A',
weightFactor: 1,
});
fairsharePolicy.addShare({
shareIdentifier: 'B',
weightFactor: 1,
});
new batch.JobQueue(this, 'JobQueue', {
schedulingPolicy: fairsharePolicy,
});
```
*Note*: The scheduler will only consider the current usage of the compute environment unless you specify `shareDecay`.
For example, a `shareDecay` of 5 minutes in the above example means that at any given point in time, twice as many `'A'` jobs
will be scheduled for each `'B'` job, but only for the past 5 minutes. If `'B'` jobs run longer than 5 minutes, then
the scheduler is allowed to put more than two `'A'` jobs for each `'B'` job, because the usage of those long-running
`'B'` jobs will no longer be considered after 5 minutes. `shareDecay` linearly decreases the usage of
long running jobs for calculation purposes. For example if share decay is 60 seconds,
then jobs that run for 30 seconds have their usage considered to be only 50% of what it actually is,
but after a whole minute the scheduler pretends they don't exist for fairness calculations.
The following code specifies a `shareDecay` of 5 minutes:
```ts
const fairsharePolicy = new batch.FairshareSchedulingPolicy(this, 'myFairsharePolicy', {
shareDecay: cdk.Duration.minutes(5),
});
```
If you have high priority jobs that should always be executed as soon as they arrive,
you can define a `computeReservation` to specify the percentage of the
maximum vCPU capacity that should be reserved for shares that are *not in the queue*.
The actual reserved percentage is defined by Batch as:
```math
(\frac{computeReservation}{100}) ^ {ActiveFairShares}
```
where `ActiveFairShares` is the number of shares for which there exists
at least one job in the queue with a unique share identifier.
This is best illustrated with an example.
Suppose there are three shares with share identifiers `A`, `B` and `C` respectively
and we specify the `computeReservation` to be 75%. The queue is currently empty,
and no other shares exist.
There are no active fair shares, since the queue is empty.
Thus (75/100)^0 = 1 = 100% of the maximum vCpus are reserved for all shares.
A job with identifier `A` enters the queue.
The number of active fair shares is now 1, hence
(75/100)^1 = .75 = 75% of the maximum vCpus are reserved for all shares that do not have the identifier `A`;
for this example, this is `B` and `C`,
(but if jobs are submitted with a share identifier not covered by this fairshare policy, those would be considered just as `B` and `C` are).
Now a `B` job enters the queue. The number of active fair shares is now 2,
so (75/100)^2 = .5625 = 56.25% of the maximum vCpus are reserved for all shares that do not have the identifier `A` or `B`.
Now a second `A` job enters the queue. The number of active fair shares is still 2,
so the percentage reserved is still 56.25%
Now a `C` job enters the queue. The number of active fair shares is now 3,
so (75/100)^3 = .421875 = 42.1875% of the maximum vCpus are reserved for all shares that do not have the identifier `A`, `B`, or `C`.
If there are no other shares that your jobs can specify, this means that 42.1875% of your capacity will never be used!
Now, `A`, `B`, and `C` can only consume 100% - 42.1875% = 57.8125% of the maximum vCpus.
Note that the this percentage is **not** split between `A`, `B`, and `C`.
Instead, the scheduler will use their `weightFactor`s to decide which jobs to schedule;
the only difference is that instead of competing for 100% of the max capacity, jobs compete for 57.8125% of the max capacity.
This example specifies a `computeReservation` of 75% that will behave as explained in the example above:
```ts
new batch.FairshareSchedulingPolicy(this, 'myFairsharePolicy', {
computeReservation: 75,
shares: [
{ weightFactor: 1, shareIdentifier: 'A' },
{ weightFactor: 0.5, shareIdentifier: 'B' },
{ weightFactor: 2, shareIdentifier: 'C' },
],
});
```
You can specify a `priority` on your `JobDefinition`s to tell the scheduler to prioritize certain jobs that share the same share identifier.
### Configuring Job Retry Policies
Certain workflows may result in Jobs failing due to intermittent issues.
Jobs can specify retry policies to respond to different failures with different actions.
There are three different ways information about the way a Job exited can be conveyed;
* `exitCode`: the exit code returned from the process executed by the container. Will only match non-zero exit codes.
* `reason`: any middleware errors, like your Docker registry being down.
* `statusReason`: infrastructure errors, most commonly your spot instance being reclaimed.
For most use cases, only one of these will be associated with a particular action at a time.
To specify common `exitCode`s, `reason`s, or `statusReason`s, use the corresponding value from
the `Reason` class. This example shows some common failure reasons:
```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
}),
retryAttempts: 5,
retryStrategies: [
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.CANNOT_PULL_CONTAINER),
],
});
jobDefn.addRetryStrategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.SPOT_INSTANCE_RECLAIMED),
);
jobDefn.addRetryStrategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.CANNOT_PULL_CONTAINER),
);
jobDefn.addRetryStrategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.custom({
onExitCode: '40*',
onReason: 'some reason',
})),
);
```
When specifying a custom reason,
you can specify a glob string to match each of these and react to different failures accordingly.
Up to five different retry strategies can be configured for each Job,
and each strategy can match against some or all of `exitCode`, `reason`, and `statusReason`.
You can optionally configure the number of times a job will be retried,
but you cannot configure different retry counts for different strategies; they all share the same count.
If multiple conditions are specified in a given retry strategy,
they must all match for the action to be taken; the conditions are ANDed together, not ORed.
### Running single-container ECS workflows
Batch can run jobs on ECS or EKS. ECS jobs can be defined as single container or multinode.
This example creates a `JobDefinition` that runs a single container with ECS:
```ts
declare const myFileSystem: efs.IFileSystem;
declare const myJobRole: iam.Role;
myFileSystem.grantRead(myJobRole);
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
volumes: [batch.EcsVolume.efs({
name: 'myVolume',
fileSystem: myFileSystem,
containerPath: '/Volumes/myVolume',
useJobRole: true,
})],
jobRole: myJobRole,
}),
});
```
For workflows that need persistent storage, batch supports mounting `Volume`s to the container.
You can both provision the volume and mount it to the container in a single operation:
```ts
declare const myFileSystem: efs.IFileSystem;
declare const jobDefn: batch.EcsJobDefinition;
jobDefn.container.addVolume(batch.EcsVolume.efs({
name: 'myVolume',
fileSystem: myFileSystem,
containerPath: '/Volumes/myVolume',
}));
```
### Running an ECS workflow with Fargate container
```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsFargateContainerDefinition(this, 'myFargateContainer', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
ephemeralStorageSize: cdk.Size.gibibytes(100),
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
}),
});
```
### Enable Execute Command (ECS Exec)
You can enable [ECS Exec](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html) for interactive debugging and troubleshooting by setting `enableExecuteCommand` to `true`.
When enabled, you'll be able to execute commands interactively in running containers.
```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'Ec2Container', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
enableExecuteCommand: true, // Enable ECS Exec
}),
});
```
The same functionality is available for Fargate containers:
```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsFargateContainerDefinition(this, 'FargateContainer', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
enableExecuteCommand: true, // Enable ECS Exec for Fargate
}),
});
```
When `enableExecuteCommand` is set to `true`:
- If no `jobRole` is provided, a new IAM role will be automatically created with the required SSM permissions
- If a `jobRole` is already provided, the necessary SSM permissions will be added to the existing role
### Secrets
You can expose SecretsManager Secret ARNs or SSM Parameters to your container as environment variables.
The following example defines the `MY_SECRET_ENV_VAR` environment variable that contains the
ARN of the Secret defined by `mySecret`:
```ts
declare const mySecret: secretsmanager.ISecret;
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
secrets: {
MY_SECRET_ENV_VAR: batch.Secret.fromSecretsManager(mySecret),
}
}),
});
```
### Running Kubernetes Workflows
Batch also supports running workflows on EKS. The following example creates a `JobDefinition` that runs on EKS:
```ts
const jobDefn = new batch.EksJobDefinition(this, 'eksf2', {
container: new batch.EksContainerDefinition(this, 'container', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
volumes: [batch.EksVolume.emptyDir({
name: 'myEmptyDirVolume',
mountPath: '/mount/path',
medium: batch.EmptyDirMediumType.MEMORY,
readonly: true,
sizeLimit: cdk.Size.mebibytes(2048),
})],
}),
});
```
You can mount `Volume`s to these containers in a single operation:
```ts
declare const jobDefn: batch.EksJobDefinition;
jobDefn.container.addVolume(batch.EksVolume.emptyDir({
name: 'emptyDir',
mountPath: '/Volumes/emptyDir',
}));
jobDefn.container.addVolume(batch.EksVolume.hostPath({
name: 'hostPath',
hostPath: '/sys',
mountPath: '/Volumes/hostPath',
}));
jobDefn.container.addVolume(batch.EksVolume.secret({
name: 'secret',
optional: true,
mountPath: '/Volumes/secret',
secretName: 'mySecret',
}));
```
### Running Distributed Workflows
Some workflows benefit from parallellization and are most powerful when run in a distributed environment,
such as certain numerical calculations or simulations. Batch offers `MultiNodeJobDefinition`s,
which allow a single job to run on multiple instances in parallel, for this purpose.
Message Passing Interface (MPI) is often used with these workflows.
You must configure your containers to use MPI properly,
but Batch allows different nodes running different containers to communicate easily with one another.
You must configure your containers to use certain environment variables that Batch will provide them,
which lets them know which one is the main node, among other information.
For an in-depth example on using MPI to perform numerical computations on Batch,
see this [blog post](https://aws.amazon.com/blogs/compute/building-a-tightly-coupled-molecular-dynamics-workflow-with-multi-node-parallel-jobs-in-aws-batch/)
In particular, the environment variable that tells the containers which one is the main node can be configured on your `MultiNodeJobDefinition` as follows:
```ts
const multiNodeJob = new batch.MultiNodeJobDefinition(this, 'JobDefinition', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R4, ec2.InstanceSize.LARGE), // optional, omit to let Batch choose the type for you
containers: [{
container: new batch.EcsEc2ContainerDefinition(this, 'mainMPIContainer', {
image: ecs.ContainerImage.fromRegistry('yourregsitry.com/yourMPIImage:latest'),
cpu: 256,
memory: cdk.Size.mebibytes(2048),
}),
startNode: 0,
endNode: 5,
}],
});
// convenience method
multiNodeJob.addContainer({
startNode: 6,
endNode: 10,
container: new batch.EcsEc2ContainerDefinition(this, 'multiContainer', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
cpu: 256,
memory: cdk.Size.mebibytes(2048),
}),
});
```
If you need to set the control node to an index other than 0, specify it in directly:
```ts
const multiNodeJob = new batch.MultiNodeJobDefinition(this, 'JobDefinition', {
mainNode: 5,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R4, ec2.InstanceSize.LARGE),
});
```
### Pass Parameters to a Job
Batch allows you define parameters in your `JobDefinition`, which can be referenced in the container command. For example:
```ts
new batch.EcsJobDefinition(this, 'JobDefn', {
parameters: { echoParam: 'foobar' },
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
command: [
'echo',
'Ref::echoParam',
],
}),
});
```
### Job Definition Version Management
By default, when you update a Job Definition, AWS Batch automatically deregisters the previous revision.
This means any jobs that were submitted using the old revision may fail if they haven't started yet.
You can preserve previous revisions by setting `skipDeregisterOnUpdate` to `true`:
```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
}),
skipDeregisterOnUpdate: true, // Keep previous revisions active
});
```
* This applies to all Job Definition types: ECS (EC2 and Fargate), EKS, and MultiNode
* Default behavior (when not specified) follows AWS Batch defaults: previous revisions are deregistered
### Understanding Progressive Allocation Strategies
AWS Batch uses an [allocation strategy](https://docs.aws.amazon.com/batch/latest/userguide/allocation-strategies.html) to determine what compute resource will efficiently handle incoming job requests. By default, **BEST_FIT** will pick an available compute instance based on vCPU requirements. If none exist, the job will wait until resources become available. However, with this strategy, you may have jobs waiting in the queue unnecessarily despite having more powerful instances available. Below is an example of how that situation might look like:
```plaintext
Compute Environment:
1. m5.xlarge => 4 vCPU
2. m5.2xlarge => 8 vCPU
```
```plaintext
Job Queue:
---------
| A | B |
---------
Job Requirements:
A => 4 vCPU - ALLOCATED TO m5.xlarge
B => 2 vCPU - WAITING
```
In this situation, Batch will allocate **Job A** to compute resource #1 because it is the most cost efficient resource that matches the vCPU requirement. However, with this `BEST_FIT` strategy, **Job B** will not be allocated to our other available compute resource even though it is strong enough to handle it. Instead, it will wait until the first job is finished processing or wait a similar `m5.xlarge` resource to be provisioned.
The alternative would be to use the `BEST_FIT_PROGRESSIVE` strategy in order for the remaining job to be handled in larger containers regardless of vCPU requirement and costs.
### Permissions
You can grant any Principal the `batch:submitJob` permission on both a job definition and a job queue like this:
```ts
declare const vpc: ec2.IVpc;
const ecsJob = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
}),
});
const queue = new batch.JobQueue(this, 'JobQueue', {
computeEnvironments: [{
computeEnvironment: new batch.ManagedEc2EcsComputeEnvironment(this, 'managedEc2CE', {
vpc,
}),
order: 1,
}],
priority: 10,
});
const user = new iam.User(this, 'MyUser');
ecsJob.grantSubmitJob(user, queue);
```

1
cdk/node_modules/aws-cdk-lib/aws-batch/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export * from './lib';

1
cdk/node_modules/aws-cdk-lib/aws-batch/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,90 @@
import type { Construct } from 'constructs';
import type * as iam from '../../aws-iam';
import type { IResource } from '../../core';
import { Resource } from '../../core';
import type { ComputeEnvironmentReference, IComputeEnvironmentRef } from '../../interfaces/generated/aws-batch-interfaces.generated';
/**
* Represents a ComputeEnvironment
*/
export interface IComputeEnvironment extends IResource, IComputeEnvironmentRef {
/**
* The name of the ComputeEnvironment
*
* @attribute
*/
readonly computeEnvironmentName: string;
/**
* The ARN of this compute environment.
*
* @attribute
*/
readonly computeEnvironmentArn: string;
/**
* The role Batch uses to perform actions on your behalf
* in your account, such as provision instances to run your jobs
*
* @default - a serviceRole will be created for managed CEs, none for unmanaged CEs
*/
readonly serviceRole?: iam.IRole;
/**
* Whether or not this ComputeEnvironment can accept jobs from a Queue.
* Enabled ComputeEnvironments can accept jobs from a Queue and
* can scale instances up or down.
* Disabled ComputeEnvironments cannot accept jobs from a Queue or
* scale instances up or down.
*
* If you change a ComputeEnvironment from enabled to disabled while it is executing jobs,
* Jobs in the `STARTED` or `RUNNING` states will not
* be interrupted. As jobs complete, the ComputeEnvironment will scale instances down to `minvCpus`.
*
* To ensure you aren't billed for unused capacity, set `minvCpus` to `0`.
*/
readonly enabled: boolean;
}
/**
* Props common to all ComputeEnvironments
*/
export interface ComputeEnvironmentProps {
/**
* The name of the ComputeEnvironment
*
* @default - generated by CloudFormation
*/
readonly computeEnvironmentName?: string;
/**
* The role Batch uses to perform actions on your behalf
* in your account, such as provision instances to run your jobs
*
* @default - a serviceRole will be created for managed CEs, none for unmanaged CEs
*/
readonly serviceRole?: iam.IRole;
/**
* Whether or not this ComputeEnvironment can accept jobs from a Queue.
* Enabled ComputeEnvironments can accept jobs from a Queue and
* can scale instances up or down.
* Disabled ComputeEnvironments cannot accept jobs from a Queue or
* scale instances up or down.
*
* If you change a ComputeEnvironment from enabled to disabled while it is executing jobs,
* Jobs in the `STARTED` or `RUNNING` states will not
* be interrupted. As jobs complete, the ComputeEnvironment will scale instances down to `minvCpus`.
*
* To ensure you aren't billed for unused capacity, set `minvCpus` to `0`.
*
* @default true
*/
readonly enabled?: boolean;
}
/**
* Abstract base class for ComputeEnvironments
*
* @internal
*/
export declare abstract class ComputeEnvironmentBase extends Resource implements IComputeEnvironment {
abstract readonly computeEnvironmentName: string;
readonly serviceRole?: iam.IRole | undefined;
readonly enabled: boolean;
abstract readonly computeEnvironmentArn: string;
get computeEnvironmentRef(): ComputeEnvironmentReference;
constructor(scope: Construct, id: string, props?: ComputeEnvironmentProps);
}

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ComputeEnvironmentBase=void 0;var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class ComputeEnvironmentBase extends core_1().Resource{serviceRole;enabled;get computeEnvironmentRef(){return{computeEnvironmentArn:this.computeEnvironmentArn}}constructor(scope,id,props){super(scope,id,{physicalName:props?.computeEnvironmentName}),this.serviceRole=props?.serviceRole,this.enabled=props?.enabled??!0}}exports.ComputeEnvironmentBase=ComputeEnvironmentBase;

View File

@@ -0,0 +1,803 @@
import type { IConstruct } from 'constructs';
import { Construct } from 'constructs';
import type { CfnJobDefinition } from './batch.generated';
import type { LinuxParameters } from './linux-parameters';
import type * as ecs from '../../aws-ecs';
import type { IFileSystem } from '../../aws-efs';
import * as iam from '../../aws-iam';
import type * as secretsmanager from '../../aws-secretsmanager';
import type * as ssm from '../../aws-ssm';
import type { Size } from '../../core';
import type { IFileSystemRef } from '../../interfaces/generated/aws-efs-interfaces.generated';
/**
* Specify the secret's version id or version stage
*/
export interface SecretVersionInfo {
/**
* version id of the secret
*
* @default - use default version id
*/
readonly versionId?: string;
/**
* version stage of the secret
*
* @default - use default version stage
*/
readonly versionStage?: string;
}
/**
* A secret environment variable.
*/
export declare abstract class Secret {
/**
* Creates an environment variable value from a parameter stored in AWS
* Systems Manager Parameter Store.
*/
static fromSsmParameter(parameter: ssm.IParameter): Secret;
/**
* Creates a environment variable value from a secret stored in AWS Secrets
* Manager.
*
* @param secret the secret stored in AWS Secrets Manager
* @param field the name of the field with the value that you want to set as
* the environment variable value. Only values in JSON format are supported.
* If you do not specify a JSON field, then the full content of the secret is
* used.
*/
static fromSecretsManager(secret: secretsmanager.ISecret, field?: string): Secret;
/**
* Creates a environment variable value from a secret stored in AWS Secrets
* Manager.
*
* @param secret the secret stored in AWS Secrets Manager
* @param versionInfo the version information to reference the secret
* @param field the name of the field with the value that you want to set as
* the environment variable value. Only values in JSON format are supported.
* If you do not specify a JSON field, then the full content of the secret is
* used.
*/
static fromSecretsManagerVersion(secret: secretsmanager.ISecret, versionInfo: SecretVersionInfo, field?: string): Secret;
/**
* The ARN of the secret
*/
abstract readonly arn: string;
/**
* Whether this secret uses a specific JSON field
*/
abstract readonly hasField?: boolean;
/**
* Grants reading the secret to a principal
* [disable-awslint:no-grants]
*/
abstract grantRead(grantee: iam.IGrantable): iam.Grant;
}
/**
* Options to configure an EcsVolume
*/
export interface EcsVolumeOptions {
/**
* the name of this volume
*/
readonly name: string;
/**
* the path on the container where this volume is mounted
*/
readonly containerPath: string;
/**
* if set, the container will have readonly access to the volume
*
* @default false
*/
readonly readonly?: boolean;
}
/**
* Represents a Volume that can be mounted to a container that uses ECS
*/
export declare abstract class EcsVolume {
/**
* Creates a Volume that uses an AWS Elastic File System (EFS); this volume can grow and shrink as needed
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/efs-volumes.html
*/
static efs(options: EfsVolumeOptions): EfsVolume;
/**
* Creates a Host volume. This volume will persist on the host at the specified `hostPath`.
* If the `hostPath` is not specified, Docker will choose the host path. In this case,
* the data may not persist after the containers that use it stop running.
*/
static host(options: HostVolumeOptions): HostVolume;
/**
* The name of this volume
*/
readonly name: string;
/**
* The path on the container that this volume will be mounted to
*/
readonly containerPath: string;
/**
* Whether or not the container has readonly access to this volume
*
* @default false
*/
readonly readonly?: boolean;
constructor(options: EcsVolumeOptions);
}
/**
* Options for configuring an EfsVolume
*/
export interface EfsVolumeOptions extends EcsVolumeOptions {
/**
* The EFS File System that supports this volume
*/
readonly fileSystem: IFileSystemRef;
/**
* The directory within the Amazon EFS file system to mount as the root directory inside the host.
* If this parameter is omitted, the root of the Amazon EFS volume is used instead.
* Specifying `/` has the same effect as omitting this parameter.
* The maximum length is 4,096 characters.
*
* @default - root of the EFS File System
*/
readonly rootDirectory?: string;
/**
* Enables encryption for Amazon EFS data in transit between the Amazon ECS host and the Amazon EFS server
*
* @see https://docs.aws.amazon.com/efs/latest/ug/encryption-in-transit.html
*
* @default false
*/
readonly enableTransitEncryption?: boolean;
/**
* The port to use when sending encrypted data between the Amazon ECS host and the Amazon EFS server.
* The value must be between 0 and 65,535.
*
* @see https://docs.aws.amazon.com/efs/latest/ug/efs-mount-helper.html
*
* @default - chosen by the EFS Mount Helper
*/
readonly transitEncryptionPort?: number;
/**
* The Amazon EFS access point ID to use.
* If an access point is specified, `rootDirectory` must either be omitted or set to `/`
* which enforces the path set on the EFS access point.
* If an access point is used, `enableTransitEncryption` must be `true`.
*
* @see https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html
*
* @default - no accessPointId
*/
readonly accessPointId?: string;
/**
* Whether or not to use the AWS Batch job IAM role defined in a job definition when mounting the Amazon EFS file system.
* If specified, `enableTransitEncryption` must be `true`.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/efs-volumes.html#efs-volume-accesspoints
*
* @default false
*/
readonly useJobRole?: boolean;
}
/**
* A Volume that uses an AWS Elastic File System (EFS); this volume can grow and shrink as needed
*/
export declare class EfsVolume extends EcsVolume {
/**
* Returns true if x is an EfsVolume, false otherwise
*/
static isEfsVolume(x: any): x is EfsVolume;
private readonly _fileSystem;
/**
* The EFS File System that supports this volume
*/
get fileSystem(): IFileSystem;
/**
* @internal
*/
get _fileSystemRef(): IFileSystemRef;
/**
* The directory within the Amazon EFS file system to mount as the root directory inside the host.
* If this parameter is omitted, the root of the Amazon EFS volume is used instead.
* Specifying `/` has the same effect as omitting this parameter.
* The maximum length is 4,096 characters.
*
* @default - root of the EFS File System
*/
readonly rootDirectory?: string;
/**
* Enables encryption for Amazon EFS data in transit between the Amazon ECS host and the Amazon EFS server
*
* @see https://docs.aws.amazon.com/efs/latest/ug/encryption-in-transit.html
*
* @default false
*/
readonly enableTransitEncryption?: boolean;
/**
* The port to use when sending encrypted data between the Amazon ECS host and the Amazon EFS server.
* The value must be between 0 and 65,535.
*
* @see https://docs.aws.amazon.com/efs/latest/ug/efs-mount-helper.html
*
* @default - chosen by the EFS Mount Helper
*/
readonly transitEncryptionPort?: number;
/**
* The Amazon EFS access point ID to use.
* If an access point is specified, `rootDirectory` must either be omitted or set to `/`
* which enforces the path set on the EFS access point.
* If an access point is used, `enableTransitEncryption` must be `true`.
*
* @see https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html
*
* @default - no accessPointId
*/
readonly accessPointId?: string;
/**
* Whether or not to use the AWS Batch job IAM role defined in a job definition when mounting the Amazon EFS file system.
* If specified, `enableTransitEncryption` must be `true`.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/efs-volumes.html#efs-volume-accesspoints
*
* @default false
*/
readonly useJobRole?: boolean;
constructor(options: EfsVolumeOptions);
}
/**
* Options for configuring an ECS HostVolume
*/
export interface HostVolumeOptions extends EcsVolumeOptions {
/**
* The path on the host machine this container will have access to
*
* @default - Docker will choose the host path.
* The data may not persist after the containers that use it stop running.
*/
readonly hostPath?: string;
}
/**
* Creates a Host volume. This volume will persist on the host at the specified `hostPath`.
* If the `hostPath` is not specified, Docker will choose the host path. In this case,
* the data may not persist after the containers that use it stop running.
*/
export declare class HostVolume extends EcsVolume {
/**
* returns `true` if `x` is a `HostVolume`, `false` otherwise
*/
static isHostVolume(x: any): x is HostVolume;
/**
* The path on the host machine this container will have access to
*/
readonly hostPath?: string;
constructor(options: HostVolumeOptions);
}
/**
* A container that can be run with ECS orchestration
*/
export interface IEcsContainerDefinition extends IConstruct {
/**
* The image that this container will run
*/
readonly image: ecs.ContainerImage;
/**
* The number of vCPUs reserved for the container.
* Each vCPU is equivalent to 1,024 CPU shares.
* For containers running on EC2 resources, you must specify at least one vCPU.
*/
readonly cpu: number;
/**
* The memory hard limit present to the container.
* If your container attempts to exceed the memory specified, the container is terminated.
* You must specify at least 4 MiB of memory for a job.
*/
readonly memory: Size;
/**
* The command that's passed to the container
*
* @see https://docs.docker.com/engine/reference/builder/#cmd
*/
readonly command?: string[];
/**
* The environment variables to pass to a container.
* Cannot start with `AWS_BATCH`.
* We don't recommend using plaintext environment variables for sensitive information, such as credential data.
*
* @default - no environment variables
*/
readonly environment?: {
[key: string]: string;
};
/**
* The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/execution-IAM-role.html
*/
readonly executionRole: iam.IRole;
/**
* The role that the container can assume.
*
* @default - no jobRole
*
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
*/
readonly jobRole?: iam.IRole;
/**
* Linux-specific modifications that are applied to the container, such as details for device mappings.
*
* @default none
*/
readonly linuxParameters?: LinuxParameters;
/**
* The configuration of the log driver
*/
readonly logDriverConfig?: ecs.LogDriverConfig;
/**
* Gives the container readonly access to its root filesystem.
*
* @default false
*/
readonly readonlyRootFilesystem?: boolean;
/**
* A map from environment variable names to the secrets for the container. Allows your job definitions
* to reference the secret by the environment variable name defined in this property.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/specifying-sensitive-data.html
*
* @default - no secrets
*/
readonly secrets?: {
[envVarName: string]: Secret;
};
/**
* The user name to use inside the container
*
* @default - no user
*/
readonly user?: string;
/**
* The volumes to mount to this container. Automatically added to the job definition.
*
* @default - no volumes
*/
readonly volumes: EcsVolume[];
/**
* Whether to enable ecs exec for this container.
*
* @default undefined - AWS Batch default is false
*/
readonly enableExecuteCommand?: boolean;
/**
* Renders this container to CloudFormation
*
* @internal
*/
_renderContainerDefinition(): CfnJobDefinition.ContainerPropertiesProperty;
/**
* Add a Volume to this container
*/
addVolume(volume: EcsVolume): void;
}
/**
* Props to configure an EcsContainerDefinition
*/
export interface EcsContainerDefinitionProps {
/**
* The image that this container will run
*/
readonly image: ecs.ContainerImage;
/**
* The number of vCPUs reserved for the container.
* Each vCPU is equivalent to 1,024 CPU shares.
* For containers running on EC2 resources, you must specify at least one vCPU.
*/
readonly cpu: number;
/**
* The memory hard limit present to the container.
* If your container attempts to exceed the memory specified, the container is terminated.
* You must specify at least 4 MiB of memory for a job.
*/
readonly memory: Size;
/**
* The command that's passed to the container
*
* @see https://docs.docker.com/engine/reference/builder/#cmd
*
* @default - no command
*/
readonly command?: string[];
/**
* The environment variables to pass to a container.
* Cannot start with `AWS_BATCH`.
* We don't recommend using plaintext environment variables for sensitive information, such as credential data.
*
* @default - no environment variables
*/
readonly environment?: {
[key: string]: string;
};
/**
* The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/execution-IAM-role.html
*
* @default - a Role will be created
*/
readonly executionRole?: iam.IRole;
/**
* The role that the container can assume.
*
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
*
* @default - no job role
*/
readonly jobRole?: iam.IRole;
/**
* Linux-specific modifications that are applied to the container, such as details for device mappings.
*
* @default none
*/
readonly linuxParameters?: LinuxParameters;
/**
* The loging configuration for this Job
*
* @default - the log configuration of the Docker daemon
*/
readonly logging?: ecs.LogDriver;
/**
* Gives the container readonly access to its root filesystem.
*
* @default false
*/
readonly readonlyRootFilesystem?: boolean;
/**
* A map from environment variable names to the secrets for the container. Allows your job definitions
* to reference the secret by the environment variable name defined in this property.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/specifying-sensitive-data.html
*
* @default - no secrets
*/
readonly secrets?: {
[envVarName: string]: Secret;
};
/**
* The user name to use inside the container
*
* @default - no user
*/
readonly user?: string;
/**
* The volumes to mount to this container. Automatically added to the job definition.
*
* @default - no volumes
*/
readonly volumes?: EcsVolume[];
/**
* Determines whether execute command functionality is turned on for this task.
*
* If true, execute command functionality is turned on all the containers in the task.
*
* This allows you to use ECS Exec to access containers interactively.
* When enabled, a job role with required SSM permissions will be created automatically if no job role is provided.
* If a job role is alreadyprovided, the required permissions will be added to it.
*
* @default undefined - AWS Batch default is false
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html
*/
readonly enableExecuteCommand?: boolean;
}
/**
* Abstract base class for ECS Containers
*/
declare abstract class EcsContainerDefinitionBase extends Construct implements IEcsContainerDefinition {
readonly image: ecs.ContainerImage;
readonly cpu: number;
readonly memory: Size;
readonly command?: string[];
readonly environment?: {
[key: string]: string;
};
readonly executionRole: iam.IRole;
readonly jobRole?: iam.IRole;
readonly linuxParameters?: LinuxParameters;
readonly logDriverConfig?: ecs.LogDriverConfig;
readonly readonlyRootFilesystem?: boolean;
readonly secrets?: {
[envVarName: string]: Secret;
};
readonly user?: string;
readonly volumes: EcsVolume[];
readonly enableExecuteCommand?: boolean;
private readonly imageConfig;
constructor(scope: Construct, id: string, props: EcsContainerDefinitionProps);
/**
* @internal
*/
_renderContainerDefinition(): CfnJobDefinition.ContainerPropertiesProperty;
addVolume(volume: EcsVolume): void;
/**
* @internal
*/
protected _renderResourceRequirements(): {
type: string;
value: string;
}[];
/**
* Handles job role setup for ECS Exec functionality
* @internal
*/
private handleJobRoleForEcsExec;
/**
* Creates a new job role with ECS Exec permissions
* @internal
*/
private createJobRoleWithEcsExecPermissions;
/**
* Adds ECS Exec required permissions to a role
* @internal
*/
private addEcsExecPermissions;
}
/**
* Sets limits for a resource with `ulimit` on linux systems.
* Used by the Docker daemon.
*/
export interface Ulimit {
/**
* The hard limit for this resource. The container will
* be terminated if it exceeds this limit.
*/
readonly hardLimit: number;
/**
* The resource to limit
*/
readonly name: UlimitName;
/**
* The reservation for this resource. The container will
* not be terminated if it exceeds this limit.
*/
readonly softLimit: number;
}
/**
* The resources to be limited
*/
export declare enum UlimitName {
/**
* max core dump file size
*/
CORE = "core",
/**
* max cpu time (seconds) for a process
*/
CPU = "cpu",
/**
* max data segment size
*/
DATA = "data",
/**
* max file size
*/
FSIZE = "fsize",
/**
* max number of file locks
*/
LOCKS = "locks",
/**
* max locked memory
*/
MEMLOCK = "memlock",
/**
* max POSIX message queue size
*/
MSGQUEUE = "msgqueue",
/**
* max nice value for any process this user is running
*/
NICE = "nice",
/**
* maximum number of open file descriptors
*/
NOFILE = "nofile",
/**
* maximum number of processes
*/
NPROC = "nproc",
/**
* size of the process' resident set (in pages)
*/
RSS = "rss",
/**
* max realtime priority
*/
RTPRIO = "rtprio",
/**
* timeout for realtime tasks
*/
RTTIME = "rttime",
/**
* max number of pending signals
*/
SIGPENDING = "sigpending",
/**
* max stack size (in bytes)
*/
STACK = "stack"
}
/**
* A container orchestrated by ECS that uses EC2 resources
*/
export interface IEcsEc2ContainerDefinition extends IEcsContainerDefinition {
/**
* When this parameter is true, the container is given elevated permissions on the host container instance (similar to the root user).
*
* @default false
*/
readonly privileged?: boolean;
/**
* Limits to set for the user this docker container will run as
*/
readonly ulimits: Ulimit[];
/**
* The number of physical GPUs to reserve for the container.
* Make sure that the number of GPUs reserved for all containers in a job doesn't exceed
* the number of available GPUs on the compute resource that the job is launched on.
*
* @default - no gpus
*/
readonly gpu?: number;
/**
* Add a ulimit to this container
*/
addUlimit(ulimit: Ulimit): void;
}
/**
* Props to configure an EcsEc2ContainerDefinition
*/
export interface EcsEc2ContainerDefinitionProps extends EcsContainerDefinitionProps {
/**
* When this parameter is true, the container is given elevated permissions on the host container instance (similar to the root user).
*
* @default false
*/
readonly privileged?: boolean;
/**
* Limits to set for the user this docker container will run as
*
* @default - no ulimits
*/
readonly ulimits?: Ulimit[];
/**
* The number of physical GPUs to reserve for the container.
* Make sure that the number of GPUs reserved for all containers in a job doesn't exceed
* the number of available GPUs on the compute resource that the job is launched on.
*
* @default - no gpus
*/
readonly gpu?: number;
}
/**
* A container orchestrated by ECS that uses EC2 resources
*/
export declare class EcsEc2ContainerDefinition extends EcsContainerDefinitionBase implements IEcsEc2ContainerDefinition {
/**
* Uniquely identifies this class.
*/
static readonly PROPERTY_INJECTION_ID: string;
readonly privileged?: boolean;
readonly ulimits: Ulimit[];
readonly gpu?: number;
constructor(scope: Construct, id: string, props: EcsEc2ContainerDefinitionProps);
/**
* @internal
*/
_renderContainerDefinition(): CfnJobDefinition.ContainerPropertiesProperty;
/**
* Add a ulimit to this container
*/
addUlimit(ulimit: Ulimit): void;
/**
* @internal
*/
protected _renderResourceRequirements(): {
type: string;
value: string;
}[];
}
/**
* A container orchestrated by ECS that uses Fargate resources and is orchestrated by ECS
*/
export interface IEcsFargateContainerDefinition extends IEcsContainerDefinition {
/**
* Indicates whether the job has a public IP address.
* For a job that's running on Fargate resources in a private subnet to send outbound traffic to the internet
* (for example, to pull container images), the private subnet requires a NAT gateway be attached to route requests to the internet.
*
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html
*
* @default false
*/
readonly assignPublicIp?: boolean;
/**
* Which version of Fargate to use when running this container
*
* @default LATEST
*/
readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;
/**
* The size for ephemeral storage.
*
* @default - 20 GiB
*/
readonly ephemeralStorageSize?: Size;
/**
* The vCPU architecture of Fargate Runtime.
*
* @default - X86_64
*/
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
/**
* The operating system for the compute environment.
*
* @default - LINUX
*/
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
}
/**
* Props to configure an EcsFargateContainerDefinition
*/
export interface EcsFargateContainerDefinitionProps extends EcsContainerDefinitionProps {
/**
* Indicates whether the job has a public IP address.
* For a job that's running on Fargate resources in a private subnet to send outbound traffic to the internet
* (for example, to pull container images), the private subnet requires a NAT gateway be attached to route requests to the internet.
*
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html
*
* @default false
*/
readonly assignPublicIp?: boolean;
/**
* Which version of Fargate to use when running this container
*
* @default LATEST
*/
readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;
/**
* The size for ephemeral storage.
*
* @default - 20 GiB
*/
readonly ephemeralStorageSize?: Size;
/**
* The vCPU architecture of Fargate Runtime.
*
* @default - X86_64
*/
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
/**
* The operating system for the compute environment.
*
* @default - LINUX
*/
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
}
/**
* A container orchestrated by ECS that uses Fargate resources
*/
export declare class EcsFargateContainerDefinition extends EcsContainerDefinitionBase implements IEcsFargateContainerDefinition {
/**
* Uniquely identifies this class.
*/
static readonly PROPERTY_INJECTION_ID: string;
readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;
readonly assignPublicIp?: boolean;
readonly ephemeralStorageSize?: Size;
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
constructor(scope: Construct, id: string, props: EcsFargateContainerDefinitionProps);
/**
* @internal
*/
_renderContainerDefinition(): CfnJobDefinition.ContainerPropertiesProperty;
}
export {};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,73 @@
import type { Construct } from 'constructs';
import type { IEcsContainerDefinition } from './ecs-container-definition';
import type { IJobDefinition, JobDefinitionProps } from './job-definition-base';
import { JobDefinitionBase } from './job-definition-base';
import * as iam from '../../aws-iam';
import type { IJobQueueRef } from '../../interfaces/generated/aws-batch-interfaces.generated';
/**
* A JobDefinition that uses ECS orchestration
*/
interface IEcsJobDefinition extends IJobDefinition {
/**
* The container that this job will run
*/
readonly container: IEcsContainerDefinition;
/**
* Whether to propagate tags from the JobDefinition
* to the ECS task that Batch spawns
*
* @default false
*/
readonly propagateTags?: boolean;
}
/**
* @internal
*/
export declare enum Compatibility {
EC2 = "EC2",
FARGATE = "FARGATE"
}
/**
* Props for EcsJobDefinition
*/
export interface EcsJobDefinitionProps extends JobDefinitionProps {
/**
* The container that this job will run
*/
readonly container: IEcsContainerDefinition;
/**
* Whether to propagate tags from the JobDefinition
* to the ECS task that Batch spawns
*
* @default false
*/
readonly propagateTags?: boolean;
}
/**
* A JobDefinition that uses ECS orchestration
*
* @resource AWS::Batch::JobDefinition
*/
export declare class EcsJobDefinition extends JobDefinitionBase implements IEcsJobDefinition {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* Import a JobDefinition by its arn.
*/
static fromJobDefinitionArn(scope: Construct, id: string, jobDefinitionArn: string): IJobDefinition;
private static getJobDefinitionName;
readonly container: IEcsContainerDefinition;
readonly propagateTags?: boolean;
private readonly resource;
get jobDefinitionArn(): string;
get jobDefinitionName(): string;
constructor(scope: Construct, id: string, props: EcsJobDefinitionProps);
/**
* Grants the `batch:submitJob` permission to the identity on both this job definition and the `queue`
*
* [disable-awslint:no-grants]
*/
grantSubmitJob(identity: iam.IGrantable, queue: IJobQueueRef): void;
private renderPlatformCapabilities;
}
export {};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,733 @@
import type { IConstruct } from 'constructs';
import { Construct } from 'constructs';
import type { CfnJobDefinition } from './batch.generated';
import type * as ecs from '../../aws-ecs';
import type { Size } from '../../core';
/**
* A container that can be run with EKS orchestration on EC2 resources
*/
export interface IEksContainerDefinition extends IConstruct {
/**
* The image that this container will run
*/
readonly image: ecs.ContainerImage;
/**
* An array of arguments to the entrypoint.
* If this isn't specified, the CMD of the container image is used.
* This corresponds to the args member in the Entrypoint portion of the Pod in Kubernetes.
* Environment variable references are expanded using the container's environment.
* If the referenced environment variable doesn't exist, the reference in the command isn't changed.
* For example, if the reference is to "$(NAME1)" and the NAME1 environment variable doesn't exist,
* the command string will remain "$(NAME1)." $$ is replaced with $, and the resulting string isn't expanded.
* or example, $$(VAR_NAME) is passed as $(VAR_NAME) whether or not the VAR_NAME environment variable exists.
*
* @see https://docs.docker.com/engine/reference/builder/#cmd
* @see https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/
*/
readonly args?: string[];
/**
* The entrypoint for the container. This isn't run within a shell.
* If this isn't specified, the `ENTRYPOINT` of the container image is used.
* Environment variable references are expanded using the container's environment.
* If the referenced environment variable doesn't exist, the reference in the command isn't changed.
* For example, if the reference is to `"$(NAME1)"` and the `NAME1` environment variable doesn't exist,
* the command string will remain `"$(NAME1)."` `$$` is replaced with `$` and the resulting string isn't expanded.
* For example, `$$(VAR_NAME)` will be passed as `$(VAR_NAME)` whether or not the `VAR_NAME` environment variable exists.
*
* The entrypoint can't be updated.
*
* @see https://docs.docker.com/engine/reference/builder/#entrypoint
* @see https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/
* @see https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#entrypoint
*/
readonly command?: string[];
/**
* The environment variables to pass to this container.
*
* *Note*: Environment variables cannot start with "AWS_BATCH".
* This naming convention is reserved for variables that AWS Batch sets.
*/
readonly env?: {
[key: string]: string;
};
/**
* The image pull policy for this container
*
* @see https://kubernetes.io/docs/concepts/containers/images/#updating-images
*
* @default - `ALWAYS` if the `:latest` tag is specified, `IF_NOT_PRESENT` otherwise
*/
readonly imagePullPolicy?: ImagePullPolicy;
/**
* The name of this container
*
* @default: `'Default'`
*/
readonly name?: string;
/**
* The amount (in MiB) of memory to present to the container.
* If your container attempts to exceed the allocated memory, it will be terminated.
*
* Must be larger that 4 MiB
*
* At least one of `memoryLimit` and `memoryReservation` is required
*
* *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
* for the specific instance type that you are using.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
* @see https://docs.aws.amazon.com/batch/latest/userguide/memory-management.html
*
* @default - No memory limit
*/
readonly memoryLimit?: Size;
/**
* The soft limit (in MiB) of memory to reserve for the container.
* Your container will be given at least this much memory, but may consume more.
*
* Must be larger that 4 MiB
*
* When system memory is under heavy contention, Docker attempts to keep the
* container memory to this soft limit. However, your container can consume more
* memory when it needs to, up to either the hard limit specified with the memory
* parameter (if applicable), or all of the available memory on the container
* instance, whichever comes first.
*
* At least one of `memoryLimit` and `memoryReservation` is required.
* If both are specified, then `memoryLimit` must be equal to `memoryReservation`
*
* *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
* for the specific instance type that you are using.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
* @see https://docs.aws.amazon.com/batch/latest/userguide/memory-management.html
*
* @default - No memory reserved
*/
readonly memoryReservation?: Size;
/**
* The hard limit of CPUs to present to this container.
* Must be an even multiple of 0.25
*
* If your container attempts to exceed this limit, it will be terminated.
*
* At least one of `cpuReservation` and `cpuLimit` is required.
* If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No CPU limit
*/
readonly cpuLimit?: number;
/**
* The soft limit of CPUs to reserve for the container
* Must be an even multiple of 0.25
*
* The container will given at least this many CPUs, but may consume more.
*
* At least one of `cpuReservation` and `cpuLimit` is required.
* If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No CPUs reserved
*/
readonly cpuReservation?: number;
/**
* The hard limit of GPUs to present to this container.
*
* If your container attempts to exceed this limit, it will be terminated.
*
* If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No GPU limit
*/
readonly gpuLimit?: number;
/**
* The soft limit of CPUs to reserve for the container
* Must be an even multiple of 0.25
*
* The container will given at least this many CPUs, but may consume more.
*
* If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No GPUs reserved
*/
readonly gpuReservation?: number;
/**
* If specified, gives this container elevated permissions on the host container instance.
* The level of permissions are similar to the root user permissions.
*
* This parameter maps to `privileged` policy in the Privileged pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#volumes-and-file-systems
*
* @default false
*/
readonly privileged?: boolean;
/**
* If specified, gives this container readonly access to its root file system.
*
* This parameter maps to `ReadOnlyRootFilesystem` policy in the Volumes and file systems pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#volumes-and-file-systems
*
* @default false
*/
readonly readonlyRootFilesystem?: boolean;
/**
* If specified, the container is run as the specified group ID (`gid`).
* If this parameter isn't specified, the default is the group that's specified in the image metadata.
* This parameter maps to `RunAsGroup` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#users-and-groups
*
* @default none
*/
readonly runAsGroup?: number;
/**
* If specified, the container is run as a user with a `uid` other than 0. Otherwise, no such rule is enforced.
* This parameter maps to `RunAsUser` and `MustRunAsNonRoot` policy in the Users and groups pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#users-and-groups
*
* @default - the container is *not* required to run as a non-root user
*/
readonly runAsRoot?: boolean;
/**
* If specified, this container is run as the specified user ID (`uid`).
* This parameter maps to `RunAsUser` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#users-and-groups
*
* @default - the user that is specified in the image metadata.
*/
readonly runAsUser?: number;
/**
* The Volumes to mount to this container.
* Automatically added to the Pod.
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/
*/
readonly volumes: EksVolume[];
/**
* Mount a Volume to this container. Automatically added to the Pod.
*/
addVolume(volume: EksVolume): void;
}
/**
* Determines when the image is pulled from the registry to launch a container
*/
export declare enum ImagePullPolicy {
/**
* Every time the kubelet launches a container,
* the kubelet queries the container image registry to resolve the name to an image digest.
* If the kubelet has a container image with that exact digest cached locally,
* the kubelet uses its cached image; otherwise, the kubelet pulls the image with the resolved digest,
* and uses that image to launch the container.
*
* @see https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-by-digest-immutable-identifier
*/
ALWAYS = "Always",
/**
* The image is pulled only if it is not already present locally
*/
IF_NOT_PRESENT = "IfNotPresent",
/**
* The kubelet does not try fetching the image.
* If the image is somehow already present locally,
* the kubelet attempts to start the container; otherwise, startup fails.
* See pre-pulled images for more details.
*
* @see https://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images
*/
NEVER = "Never"
}
/**
* Props to configure an EksContainerDefinition
*/
export interface EksContainerDefinitionProps {
/**
* The image that this container will run
*/
readonly image: ecs.ContainerImage;
/**
* An array of arguments to the entrypoint.
* If this isn't specified, the CMD of the container image is used.
* This corresponds to the args member in the Entrypoint portion of the Pod in Kubernetes.
* Environment variable references are expanded using the container's environment.
* If the referenced environment variable doesn't exist, the reference in the command isn't changed.
* For example, if the reference is to "$(NAME1)" and the NAME1 environment variable doesn't exist,
* the command string will remain "$(NAME1)." $$ is replaced with $, and the resulting string isn't expanded.
* or example, $$(VAR_NAME) is passed as $(VAR_NAME) whether or not the VAR_NAME environment variable exists.
*
* @see https://docs.docker.com/engine/reference/builder/#cmd
* @see https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/
*
* @default - no args
*/
readonly args?: string[];
/**
* The entrypoint for the container. This isn't run within a shell.
* If this isn't specified, the `ENTRYPOINT` of the container image is used.
* Environment variable references are expanded using the container's environment.
* If the referenced environment variable doesn't exist, the reference in the command isn't changed.
* For example, if the reference is to `"$(NAME1)"` and the `NAME1` environment variable doesn't exist,
* the command string will remain `"$(NAME1)."` `$$` is replaced with `$` and the resulting string isn't expanded.
* For example, `$$(VAR_NAME)` will be passed as `$(VAR_NAME)` whether or not the `VAR_NAME` environment variable exists.
*
* The entrypoint can't be updated.
*
* @see https://docs.docker.com/engine/reference/builder/#entrypoint
* @see https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/
* @see https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#entrypoint
*
* @default - no command
*/
readonly command?: string[];
/**
* The environment variables to pass to this container.
*
* *Note*: Environment variables cannot start with "AWS_BATCH".
* This naming convention is reserved for variables that AWS Batch sets.
*
* @default - no environment variables
*/
readonly env?: {
[key: string]: string;
};
/**
* The image pull policy for this container
*
* @see https://kubernetes.io/docs/concepts/containers/images/#updating-images
*
* @default - `ALWAYS` if the `:latest` tag is specified, `IF_NOT_PRESENT` otherwise
*/
readonly imagePullPolicy?: ImagePullPolicy;
/**
* The name of this container
*
* @default: `'Default'`
*/
readonly name?: string;
/**
* The amount (in MiB) of memory to present to the container.
* If your container attempts to exceed the allocated memory, it will be terminated.
*
* Must be larger that 4 MiB
*
* At least one of `memoryLimit` and `memoryReservation` is required
*
* *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
* for the specific instance type that you are using.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
* @see https://docs.aws.amazon.com/batch/latest/userguide/memory-management.html
*
* @default - No memory limit
*/
readonly memoryLimit?: Size;
/**
* The soft limit (in MiB) of memory to reserve for the container.
* Your container will be given at least this much memory, but may consume more.
*
* Must be larger that 4 MiB
*
* When system memory is under heavy contention, Docker attempts to keep the
* container memory to this soft limit. However, your container can consume more
* memory when it needs to, up to either the hard limit specified with the memory
* parameter (if applicable), or all of the available memory on the container
* instance, whichever comes first.
*
* At least one of `memoryLimit` and `memoryReservation` is required.
* If both are specified, then `memoryLimit` must be equal to `memoryReservation`
*
* *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
* for the specific instance type that you are using.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
* @see https://docs.aws.amazon.com/batch/latest/userguide/memory-management.html
*
* @default - No memory reserved
*/
readonly memoryReservation?: Size;
/**
* The hard limit of CPUs to present to this container.
* Must be an even multiple of 0.25
*
* If your container attempts to exceed this limit, it will be terminated.
*
* At least one of `cpuReservation` and `cpuLimit` is required.
* If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No CPU limit
*/
readonly cpuLimit?: number;
/**
* The soft limit of CPUs to reserve for the container
* Must be an even multiple of 0.25
*
* The container will given at least this many CPUs, but may consume more.
*
* At least one of `cpuReservation` and `cpuLimit` is required.
* If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No CPUs reserved
*/
readonly cpuReservation?: number;
/**
* The hard limit of GPUs to present to this container.
*
* If your container attempts to exceed this limit, it will be terminated.
*
* If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No GPU limit
*/
readonly gpuLimit?: number;
/**
* The soft limit of CPUs to reserve for the container
* Must be an even multiple of 0.25
*
* The container will given at least this many CPUs, but may consume more.
*
* If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.
*
* @see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
*
* @default - No GPUs reserved
*/
readonly gpuReservation?: number;
/**
* If specified, gives this container elevated permissions on the host container instance.
* The level of permissions are similar to the root user permissions.
*
* This parameter maps to `privileged` policy in the Privileged pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#volumes-and-file-systems
*
* @default false
*/
readonly privileged?: boolean;
/**
* If specified, gives this container readonly access to its root file system.
*
* This parameter maps to `ReadOnlyRootFilesystem` policy in the Volumes and file systems pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#volumes-and-file-systems
*
* @default false
*/
readonly readonlyRootFilesystem?: boolean;
/**
* If specified, the container is run as the specified group ID (`gid`).
* If this parameter isn't specified, the default is the group that's specified in the image metadata.
* This parameter maps to `RunAsGroup` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#users-and-groups
*
* @default none
*/
readonly runAsGroup?: number;
/**
* If specified, the container is run as a user with a `uid` other than 0. Otherwise, no such rule is enforced.
* This parameter maps to `RunAsUser` and `MustRunAsNonRoot` policy in the Users and groups pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#users-and-groups
*
* @default - the container is *not* required to run as a non-root user
*/
readonly runAsRoot?: boolean;
/**
* If specified, this container is run as the specified user ID (`uid`).
* This parameter maps to `RunAsUser` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.
*
* *Note*: this is only compatible with Kubernetes < v1.25
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#users-and-groups
*
* @default - the user that is specified in the image metadata.
*/
readonly runAsUser?: number;
/**
* The Volumes to mount to this container.
* Automatically added to the Pod.
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/
*
* @default - no volumes
*/
readonly volumes?: EksVolume[];
}
/**
* A container that can be run with EKS orchestration on EC2 resources
*/
export declare class EksContainerDefinition extends Construct implements IEksContainerDefinition {
/**
* Uniquely identifies this class.
*/
static readonly PROPERTY_INJECTION_ID: string;
readonly image: ecs.ContainerImage;
readonly args?: string[];
readonly command?: string[];
readonly env?: {
[key: string]: string;
};
readonly imagePullPolicy?: ImagePullPolicy;
readonly name?: string;
readonly memoryLimit?: Size;
readonly memoryReservation?: Size;
readonly cpuLimit?: number;
readonly cpuReservation?: number;
readonly gpuLimit?: number;
readonly gpuReservation?: number;
readonly privileged?: boolean;
readonly readonlyRootFilesystem?: boolean;
readonly runAsGroup?: number;
readonly runAsRoot?: boolean;
readonly runAsUser?: number;
readonly volumes: EksVolume[];
private readonly imageConfig;
constructor(scope: Construct, id: string, props: EksContainerDefinitionProps);
addVolume(volume: EksVolume): void;
/**
*
* @internal
*/
_renderContainerDefinition(): CfnJobDefinition.EksContainerProperty;
}
/**
* Options to configure an EksVolume
*/
export interface EksVolumeOptions {
/**
* The name of this volume.
* The name must be a valid DNS subdomain name.
*
* @see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
*/
readonly name: string;
/**
* The path on the container where the volume is mounted.
*
* @default - the volume is not mounted
*/
readonly mountPath?: string;
/**
* If specified, the container has readonly access to the volume.
* Otherwise, the container has read/write access.
*
* @default false
*/
readonly readonly?: boolean;
}
/**
* A Volume that can be mounted to a container supported by EKS
*/
export declare abstract class EksVolume {
/**
* Creates a Kubernetes EmptyDir volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
*/
static emptyDir(options: EmptyDirVolumeOptions): EmptyDirVolume;
/**
* Creates a Kubernetes HostPath volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
*/
static hostPath(options: HostPathVolumeOptions): HostPathVolume;
/**
* Creates a Kubernetes Secret volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#secret
*/
static secret(options: SecretPathVolumeOptions): SecretPathVolume;
/**
* The name of this volume.
* The name must be a valid DNS subdomain name.
*
* @see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
*/
readonly name: string;
/**
* The path on the container where the container is mounted.
*
* @default - the container is not mounted
*/
readonly containerPath?: string;
/**
* If specified, the container has readonly access to the volume.
* Otherwise, the container has read/write access.
*
* @default false
*/
readonly readonly?: boolean;
constructor(options: EksVolumeOptions);
}
/**
* Options for a Kubernetes EmptyDir volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
*/
export interface EmptyDirVolumeOptions extends EksVolumeOptions {
/**
* The storage type to use for this Volume.
*
* @default `EmptyDirMediumType.DISK`
*/
readonly medium?: EmptyDirMediumType;
/**
* The maximum size for this Volume
*
* @default - no size limit
*/
readonly sizeLimit?: Size;
}
/**
* What medium the volume will live in
*/
export declare enum EmptyDirMediumType {
/**
* Use the disk storage of the node.
* Items written here will survive node reboots.
*/
DISK = "",
/**
* Use the `tmpfs` volume that is backed by RAM of the node.
* Items written here will *not* survive node reboots.
*/
MEMORY = "Memory"
}
/**
* A Kubernetes EmptyDir volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
*/
export declare class EmptyDirVolume extends EksVolume {
/**
* Returns `true` if `x` is an EmptyDirVolume, `false` otherwise
*/
static isEmptyDirVolume(x: any): x is EmptyDirVolume;
/**
* The storage type to use for this Volume.
*
* @default `EmptyDirMediumType.DISK`
*/
readonly medium?: EmptyDirMediumType;
/**
* The maximum size for this Volume
*
* @default - no size limit
*/
readonly sizeLimit?: Size;
constructor(options: EmptyDirVolumeOptions);
}
/**
* Options for a kubernetes HostPath volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
*/
export interface HostPathVolumeOptions extends EksVolumeOptions {
/**
* The path of the file or directory on the host to mount into containers on the pod.
*
* *Note*: HothPath Volumes present many security risks, and should be avoided when possible.
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
*/
readonly hostPath: string;
}
/**
* A Kubernetes HostPath volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
*/
export declare class HostPathVolume extends EksVolume {
/**
* returns `true` if `x` is a HostPathVolume, `false` otherwise
*/
static isHostPathVolume(x: any): x is HostPathVolume;
/**
* The path of the file or directory on the host to mount into containers on the pod.
*
* *Note*: HothPath Volumes present many security risks, and should be avoided when possible.
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
*/
readonly path: string;
constructor(options: HostPathVolumeOptions);
}
/**
* Options for a Kubernetes SecretPath Volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#secret
*/
export interface SecretPathVolumeOptions extends EksVolumeOptions {
/**
* The name of the secret.
* Must be a valid DNS subdomain name.
*
* @see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
*/
readonly secretName: string;
/**
* Specifies whether the secret or the secret's keys must be defined
*
* @default true
*/
readonly optional?: boolean;
}
/**
* Specifies the configuration of a Kubernetes secret volume
*
* @see https://kubernetes.io/docs/concepts/storage/volumes/#secret
*/
export declare class SecretPathVolume extends EksVolume {
/**
* returns `true` if `x` is a `SecretPathVolume` and `false` otherwise
*/
static isSecretPathVolume(x: any): x is SecretPathVolume;
/**
* The name of the secret.
* Must be a valid DNS subdomain name.
*
* @see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
*/
readonly secretName: string;
/**
* Specifies whether the secret or the secret's keys must be defined
*
* @default true
*/
readonly optional?: boolean;
constructor(options: SecretPathVolumeOptions);
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,127 @@
import type { Construct } from 'constructs';
import type { EksContainerDefinition } from './eks-container-definition';
import type { IJobDefinition, JobDefinitionProps } from './job-definition-base';
import { JobDefinitionBase } from './job-definition-base';
/**
* A JobDefinition that uses Eks orchestration
*/
export interface IEksJobDefinition extends IJobDefinition {
/**
* The container this Job Definition will run
*/
readonly container: EksContainerDefinition;
/**
* The DNS Policy of the pod used by this Job Definition
*
* @see https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy
*
* @default `DnsPolicy.CLUSTER_FIRST`
*/
readonly dnsPolicy?: DnsPolicy;
/**
* If specified, the Pod used by this Job Definition will use the host's network IP address.
* Otherwise, the Kubernetes pod networking model is enabled.
* Most AWS Batch workloads are egress-only and don't require the overhead of IP allocation for each pod for incoming connections.
*
* @default true
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#host-namespaces
* @see https://kubernetes.io/docs/concepts/workloads/pods/#pod-networking
*/
readonly useHostNetwork?: boolean;
/**
* The name of the service account that's used to run the container.
* service accounts are Kubernetes method of identification and authentication,
* roughly analogous to IAM users.
*
* @see https://docs.aws.amazon.com/eks/latest/userguide/service-accounts.html
* @see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
* @see https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html
*
* @default - the default service account of the container
*/
readonly serviceAccount?: string;
}
/**
* Props for EksJobDefinition
*/
export interface EksJobDefinitionProps extends JobDefinitionProps {
/**
* The container this Job Definition will run
*/
readonly container: EksContainerDefinition;
/**
* The DNS Policy of the pod used by this Job Definition
*
* @see https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy
*
* @default `DnsPolicy.CLUSTER_FIRST`
*/
readonly dnsPolicy?: DnsPolicy;
/**
* If specified, the Pod used by this Job Definition will use the host's network IP address.
* Otherwise, the Kubernetes pod networking model is enabled.
* Most AWS Batch workloads are egress-only and don't require the overhead of IP allocation for each pod for incoming connections.
*
* @default true
*
* @see https://kubernetes.io/docs/concepts/security/pod-security-policy/#host-namespaces
* @see https://kubernetes.io/docs/concepts/workloads/pods/#pod-networking
*/
readonly useHostNetwork?: boolean;
/**
* The name of the service account that's used to run the container.
* service accounts are Kubernetes method of identification and authentication,
* roughly analogous to IAM users.
*
* @see https://docs.aws.amazon.com/eks/latest/userguide/service-accounts.html
* @see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
* @see https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html
*
* @default - the default service account of the container
*/
readonly serviceAccount?: string;
}
/**
* The DNS Policy for the pod used by the Job Definition
*
* @see https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy
*/
export declare enum DnsPolicy {
/**
* The Pod inherits the name resolution configuration from the node that the Pods run on
*/
DEFAULT = "Default",
/**
* Any DNS query that does not match the configured cluster domain suffix, such as `"www.kubernetes.io"`,
* is forwarded to an upstream nameserver by the DNS server.
* Cluster administrators may have extra stub-domain and upstream DNS servers configured.
*/
CLUSTER_FIRST = "ClusterFirst",
/**
* For Pods running with `hostNetwork`, you should explicitly set its DNS policy to `CLUSTER_FIRST_WITH_HOST_NET`.
* Otherwise, Pods running with `hostNetwork` and `CLUSTER_FIRST` will fallback to the behavior of the `DEFAULT` policy.
*/
CLUSTER_FIRST_WITH_HOST_NET = "ClusterFirstWithHostNet"
}
/**
* A JobDefinition that uses Eks orchestration
*
* @resource AWS::Batch::JobDefinition
*/
export declare class EksJobDefinition extends JobDefinitionBase implements IEksJobDefinition {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* Import an EksJobDefinition by its arn
*/
static fromEksJobDefinitionArn(scope: Construct, id: string, eksJobDefinitionArn: string): IEksJobDefinition;
readonly container: EksContainerDefinition;
readonly dnsPolicy?: DnsPolicy;
readonly useHostNetwork?: boolean;
readonly serviceAccount?: string;
private readonly resource;
get jobDefinitionArn(): string;
get jobDefinitionName(): string;
constructor(scope: Construct, id: string, props: EksJobDefinitionProps);
}

File diff suppressed because one or more lines are too long

13
cdk/node_modules/aws-cdk-lib/aws-batch/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
export * from './ecs-job-definition';
export * from './compute-environment-base';
export * from './eks-job-definition';
export * from './ecs-container-definition';
export * from './eks-container-definition';
export * from './job-definition-base';
export * from './job-queue';
export * from './linux-parameters';
export * from './managed-compute-environment';
export * from './multinode-job-definition';
export * from './scheduling-policy';
export * from './unmanaged-compute-environment';
export * from './batch.generated';

1
cdk/node_modules/aws-cdk-lib/aws-batch/lib/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,235 @@
import type { Construct } from 'constructs';
import type { CfnJobDefinitionProps } from './batch.generated';
import type { Duration, IResource } from '../../core';
import { Resource } from '../../core';
import type { IJobDefinitionRef, JobDefinitionReference } from '../../interfaces/generated/aws-batch-interfaces.generated';
/**
* Represents a JobDefinition
*/
export interface IJobDefinition extends IResource, IJobDefinitionRef {
/**
* The ARN of this job definition
*
* @attribute
*/
readonly jobDefinitionArn: string;
/**
* The name of this job definition
*
* @attribute
*/
readonly jobDefinitionName: string;
/**
* The default parameters passed to the container
* These parameters can be referenced in the `command` that
* you give to the container
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/job_definition_parameters.html#parameters
*
* @default none
*/
readonly parameters?: {
[key: string]: any;
};
/**
* The number of times to retry a job.
* The job is retried on failure the same number of attempts as the value.
*
* @default 1
*/
readonly retryAttempts?: number;
/**
* Defines the retry behavior for this job
*
* @default - no `RetryStrategy`
*/
readonly retryStrategies: RetryStrategy[];
/**
* The priority of this Job. Only used in Fairshare Scheduling
* to decide which job to run first when there are multiple jobs
* with the same share identifier.
*
* @default none
*/
readonly schedulingPriority?: number;
/**
* The timeout time for jobs that are submitted with this job definition.
* After the amount of time you specify passes,
* Batch terminates your jobs if they aren't finished.
*
* @default - no timeout
*/
readonly timeout?: Duration;
/**
* Add a RetryStrategy to this JobDefinition
*/
addRetryStrategy(strategy: RetryStrategy): void;
}
/**
* Props common to all JobDefinitions
*/
export interface JobDefinitionProps {
/**
* The name of this job definition
*
* @default - generated by CloudFormation
*/
readonly jobDefinitionName?: string;
/**
* The default parameters passed to the container
* These parameters can be referenced in the `command` that
* you give to the container
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/job_definition_parameters.html#parameters
*
* @default none
*/
readonly parameters?: {
[key: string]: any;
};
/**
* The number of times to retry a job.
* The job is retried on failure the same number of attempts as the value.
*
* @default 1
*/
readonly retryAttempts?: number;
/**
* Defines the retry behavior for this job
*
* @default - no `RetryStrategy`
*/
readonly retryStrategies?: RetryStrategy[];
/**
* The priority of this Job. Only used in Fairshare Scheduling
* to decide which job to run first when there are multiple jobs
* with the same share identifier.
*
* @default none
*/
readonly schedulingPriority?: number;
/**
* The timeout time for jobs that are submitted with this job definition.
* After the amount of time you specify passes,
* Batch terminates your jobs if they aren't finished.
*
* @default - no timeout
*/
readonly timeout?: Duration;
/**
* Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.
*
* When the property is set to false, the previous revision of the job definition is de-registered after a new revision is created.
* When the property is set to true, the previous revision of the job definition is not de-registered.
*
* @default undefined - AWS Batch default is false
*/
readonly skipDeregisterOnUpdate?: boolean;
}
/**
* Define how Jobs using this JobDefinition respond to different exit conditions
*/
export declare class RetryStrategy {
/**
* Create a new RetryStrategy
*/
static of(action: Action, on: Reason): RetryStrategy;
/**
* The action to take when the job exits with the Reason specified
*/
readonly action: Action;
/**
* If the job exits with this Reason it will trigger the specified Action
*/
readonly on: Reason;
constructor(action: Action, on: Reason);
}
/**
* The Action to take when all specified conditions in a RetryStrategy are met
*/
export declare enum Action {
/**
* The job will not retry
*/
EXIT = "EXIT",
/**
* The job will retry. It can be retried up to the number of times specified in `retryAttempts`.
*/
RETRY = "RETRY"
}
/**
* The corresponding Action will only be taken if *all* of the conditions specified here are met.
*/
export interface CustomReason {
/**
* A glob string that will match on the job exit code. For example, `'40*'` will match 400, 404, 40123456789012
*
* @default - will not match on the exit code
*/
readonly onExitCode?: string;
/**
* A glob string that will match on the statusReason returned by the exiting job.
* For example, `'Host EC2*'` indicates that the spot instance has been reclaimed.
*
* @default - will not match on the status reason
*/
readonly onStatusReason?: string;
/**
* A glob string that will match on the reason returned by the exiting job
* For example, `'CannotPullContainerError*'` indicates that container needed to start the job could not be pulled.
*
* @default - will not match on the reason
*/
readonly onReason?: string;
}
/**
* Common job exit reasons
*/
export declare class Reason {
/**
* Will match any non-zero exit code
*/
static readonly NON_ZERO_EXIT_CODE: Reason;
/**
* Will only match if the Docker container could not be pulled
*/
static readonly CANNOT_PULL_CONTAINER: Reason;
/**
* Will only match if the Spot instance executing the job was reclaimed
*/
static readonly SPOT_INSTANCE_RECLAIMED: Reason;
/**
* A custom Reason that can match on multiple conditions.
* Note that all specified conditions must be met for this reason to match.
*/
static custom(customReasonProps: CustomReason): Reason;
}
/**
* Abstract base class for JobDefinitions
*
* @internal
*/
export declare abstract class JobDefinitionBase extends Resource implements IJobDefinition {
abstract readonly jobDefinitionArn: string;
abstract readonly jobDefinitionName: string;
readonly parameters?: {
[key: string]: any;
};
readonly retryAttempts?: number;
readonly retryStrategies: RetryStrategy[];
readonly schedulingPriority?: number;
readonly timeout?: Duration;
/**
* Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.
*
* @default undefined - AWS Batch default is false
*/
readonly skipDeregisterOnUpdate?: boolean;
get jobDefinitionRef(): JobDefinitionReference;
constructor(scope: Construct, id: string, props?: JobDefinitionProps);
addRetryStrategy(strategy: RetryStrategy): void;
}
/**
* @internal
*/
export declare function baseJobDefinitionProperties(baseJobDefinition: JobDefinitionBase): CfnJobDefinitionProps;

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.JobDefinitionBase=exports.Reason=exports.Action=exports.RetryStrategy=void 0,exports.baseJobDefinitionProperties=baseJobDefinitionProperties;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class RetryStrategy{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_batch.RetryStrategy",version:"2.252.0"};static of(action,on){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_Action(action),jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_Reason(on)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.of),error}return new RetryStrategy(action,on)}action;on;constructor(action,on){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_Action(action),jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_Reason(on)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,RetryStrategy),error}this.action=action,this.on=on}}exports.RetryStrategy=RetryStrategy;var Action;(function(Action2){Action2.EXIT="EXIT",Action2.RETRY="RETRY"})(Action||(exports.Action=Action={}));class Reason{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_batch.Reason",version:"2.252.0"};static NON_ZERO_EXIT_CODE={onExitCode:"*"};static CANNOT_PULL_CONTAINER={onReason:"CannotPullContainerError:*"};static SPOT_INSTANCE_RECLAIMED={onStatusReason:"Host EC2*"};static custom(customReasonProps){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_CustomReason(customReasonProps)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.custom),error}return customReasonProps}}exports.Reason=Reason;class JobDefinitionBase extends core_1().Resource{parameters;retryAttempts;retryStrategies;schedulingPriority;timeout;skipDeregisterOnUpdate;get jobDefinitionRef(){return{jobDefinitionArn:this.jobDefinitionArn}}constructor(scope,id,props){super(scope,id,{physicalName:props?.jobDefinitionName}),this.parameters=props?.parameters,this.retryAttempts=props?.retryAttempts,this.retryStrategies=props?.retryStrategies??[],this.schedulingPriority=props?.schedulingPriority,this.timeout=props?.timeout,this.skipDeregisterOnUpdate=props?.skipDeregisterOnUpdate}addRetryStrategy(strategy){this.retryStrategies.push(strategy)}}exports.JobDefinitionBase=JobDefinitionBase;function baseJobDefinitionProperties(baseJobDefinition){return{parameters:baseJobDefinition.parameters,retryStrategy:{attempts:baseJobDefinition.retryAttempts,evaluateOnExit:core_1().Lazy.any({produce:()=>{if(baseJobDefinition.retryStrategies.length!==0)return baseJobDefinition.retryStrategies.map(strategy=>({action:strategy.action,...strategy.on}))}})},schedulingPriority:baseJobDefinition.schedulingPriority,timeout:{attemptDurationSeconds:baseJobDefinition.timeout?.toSeconds()},type:"dummy",resourceRetentionPolicy:baseJobDefinition.skipDeregisterOnUpdate!==void 0?{skipDeregisterOnUpdate:baseJobDefinition.skipDeregisterOnUpdate}:void 0}}

View File

@@ -0,0 +1,232 @@
import type { Construct } from 'constructs';
import type { ISchedulingPolicy } from './scheduling-policy';
import type { Duration, IResource } from '../../core';
import { Resource } from '../../core';
import type { IComputeEnvironmentRef, IJobQueueRef, ISchedulingPolicyRef, JobQueueReference } from '../../interfaces/generated/aws-batch-interfaces.generated';
/**
* Represents a JobQueue
*/
export interface IJobQueue extends IResource, IJobQueueRef {
/**
* The name of the job queue. It can be up to 128 letters long.
* It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_)
*
* @attribute
*/
readonly jobQueueName: string;
/**
* The ARN of this job queue
*
* @attribute
*/
readonly jobQueueArn: string;
/**
* The set of compute environments mapped to a job queue and their order relative to each other.
* The job scheduler uses this parameter to determine which compute environment runs a specific job.
* Compute environments must be in the VALID state before you can associate them with a job queue.
* You can associate up to three compute environments with a job queue.
* All of the compute environments must be either EC2 (EC2 or SPOT) or Fargate (FARGATE or FARGATE_SPOT);
* EC2 and Fargate compute environments can't be mixed.
*
* *Note*: All compute environments that are associated with a job queue must share the same architecture.
* AWS Batch doesn't support mixing compute environment architecture types in a single job queue.
*/
readonly computeEnvironments: OrderedComputeEnvironment[];
/**
* The priority of the job queue.
* Job queues with a higher priority are evaluated first when associated with the same compute environment.
* Priority is determined in descending order.
* For example, a job queue with a priority value of 10 is given scheduling preference over a job queue with a priority value of 1.
*/
readonly priority: number;
/**
* If the job queue is enabled, it is able to accept jobs.
* Otherwise, new jobs can't be added to the queue, but jobs already in the queue can finish.
*
* @default true
*/
readonly enabled?: boolean;
/**
* The SchedulingPolicy for this JobQueue. Instructs the Scheduler how to schedule different jobs.
*
* @default - no scheduling policy
*/
readonly schedulingPolicy?: ISchedulingPolicy;
/**
* Add a `ComputeEnvironment` to this Queue.
* The Queue will prefer lower-order `ComputeEnvironment`s.
*/
addComputeEnvironment(computeEnvironment: IComputeEnvironmentRef, order: number): void;
}
/**
* Props to configure a JobQueue
*/
export interface JobQueueProps {
/**
* The set of compute environments mapped to a job queue and their order relative to each other.
* The job scheduler uses this parameter to determine which compute environment runs a specific job.
* Compute environments must be in the VALID state before you can associate them with a job queue.
* You can associate up to three compute environments with a job queue.
* All of the compute environments must be either EC2 (EC2 or SPOT) or Fargate (FARGATE or FARGATE_SPOT);
* EC2 and Fargate compute environments can't be mixed.
*
* *Note*: All compute environments that are associated with a job queue must share the same architecture.
* AWS Batch doesn't support mixing compute environment architecture types in a single job queue.
*
* @default none
*/
readonly computeEnvironments?: OrderedComputeEnvironment[];
/**
* The priority of the job queue.
* Job queues with a higher priority are evaluated first when associated with the same compute environment.
* Priority is determined in descending order.
* For example, a job queue with a priority of 10 is given scheduling preference over a job queue with a priority of 1.
*
* @default 1
*/
readonly priority?: number;
/**
* The name of the job queue. It can be up to 128 letters long.
* It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_)
*
* @default - no name
*/
readonly jobQueueName?: string;
/**
* If the job queue is enabled, it is able to accept jobs.
* Otherwise, new jobs can't be added to the queue, but jobs already in the queue can finish.
*
* @default true
*/
readonly enabled?: boolean;
/**
* The SchedulingPolicy for this JobQueue. Instructs the Scheduler how to schedule different jobs.
*
* @default - no scheduling policy
*/
readonly schedulingPolicy?: ISchedulingPolicyRef;
/**
* The set of actions that AWS Batch perform on jobs that remain at the head of the job queue in
* the specified state longer than specified times.
*
* @default - no actions
*/
readonly jobStateTimeLimitActions?: JobStateTimeLimitAction[];
}
/**
* Assigns an order to a ComputeEnvironment.
* The JobQueue will prioritize the lowest-order ComputeEnvironment.
*/
export interface OrderedComputeEnvironment {
/**
* The ComputeEnvironment to link to this JobQueue
*/
readonly computeEnvironment: IComputeEnvironmentRef;
/**
* The order associated with `computeEnvironment`
*/
readonly order: number;
}
/**
* Specifies an action that AWS Batch will take after the job has remained at
* the head of the queue in the specified state for longer than the specified time.
*/
export interface JobStateTimeLimitAction {
/**
* The action to take when a job is at the head of the job queue in the specified state
* for the specified period of time.
*
* @default JobStateTimeLimitActionsAction.CANCEL
*/
readonly action?: JobStateTimeLimitActionsAction;
/**
* The approximate amount of time, that must pass with the job in the specified
* state before the action is taken.
*
* The minimum value is 10 minutes and the maximum value is 24 hours.
*/
readonly maxTime: Duration;
/**
* The reason to log for the action being taken.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/troubleshooting.html#job_stuck_in_runnable
*/
readonly reason: JobStateTimeLimitActionsReason;
/**
* The state of the job needed to trigger the action.
*
* @default JobStateTimeLimitActionsState.RUNNABLE
*/
readonly state?: JobStateTimeLimitActionsState;
}
/**
* The action to take when a job is at the head of the job queue in the specified state
* for the specified period of time.
*/
export declare enum JobStateTimeLimitActionsAction {
/**
* Cancel the job.
*/
CANCEL = "CANCEL",
/**
* Terminate the job.
*/
TERMINATE = "TERMINATE"
}
/**
* The reason to log for the action being taken.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/troubleshooting.html#job_stuck_in_runnable
*/
export declare enum JobStateTimeLimitActionsReason {
/**
* All connected compute environments have insufficient capacity errors.
*/
INSUFFICIENT_INSTANCE_CAPACITY = "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY",
/**
* All compute environments have a maxvCpus parameter that is smaller than the job requirements.
*/
COMPUTE_ENVIRONMENT_MAX_RESOURCE = "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE",
/**
* None of the compute environments have instances that meet the job requirements.
*/
JOB_RESOURCE_REQUIREMENT = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT"
}
/**
* The state of the job needed to trigger the action.
*/
export declare enum JobStateTimeLimitActionsState {
/**
* RUNNABLE state triggers the action.
*/
RUNNABLE = "RUNNABLE"
}
/**
* JobQueues can receive Jobs, which are removed from the queue when
* sent to the linked ComputeEnvironment(s) to be executed.
* Jobs exit the queue in FIFO order unless a `SchedulingPolicy` is linked.
*/
export declare class JobQueue extends Resource implements IJobQueue {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* refer to an existing JobQueue by its arn
*/
static fromJobQueueArn(scope: Construct, id: string, jobQueueArn: string): IJobQueue;
private readonly _computeEnvironments;
readonly priority: number;
readonly enabled?: boolean;
private readonly _schedulingPolicy?;
private readonly resource;
get jobQueueArn(): string;
get computeEnvironments(): OrderedComputeEnvironment[];
get jobQueueName(): string;
/**
* The SchedulingPolicy for this JobQueue. Instructs the Scheduler how to schedule different jobs.
*/
get schedulingPolicy(): ISchedulingPolicy | undefined;
get jobQueueRef(): JobQueueReference;
constructor(scope: Construct, id: string, props?: JobQueueProps);
addComputeEnvironment(computeEnvironment: IComputeEnvironmentRef, order: number): void;
private renderJobStateTimeLimitActions;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,196 @@
import { Construct } from 'constructs';
import type { CfnJobDefinition } from './batch.generated';
import * as cdk from '../../core';
/**
* The properties for defining Linux-specific options that are applied to the container.
*/
export interface LinuxParametersProps {
/**
* Specifies whether to run an init process inside the container that forwards signals and reaps processes.
*
* @default false
*/
readonly initProcessEnabled?: boolean;
/**
* The value for the size of the /dev/shm volume.
*
* @default No shared memory.
*/
readonly sharedMemorySize?: cdk.Size;
/**
* The total amount of swap memory a container can use. This parameter
* will be translated to the --memory-swap option to docker run.
*
* This parameter is only supported when you are using the EC2 launch type.
* Accepted values are positive integers.
*
* @default No swap.
*/
readonly maxSwap?: cdk.Size;
/**
* This allows you to tune a container's memory swappiness behavior. This parameter
* maps to the --memory-swappiness option to docker run. The swappiness relates
* to the kernel's tendency to swap memory. A value of 0 will cause swapping to
* not happen unless absolutely necessary. A value of 100 will cause pages to
* be swapped very aggressively.
*
* This parameter is only supported when you are using the EC2 launch type.
* Accepted values are whole numbers between 0 and 100. If a value is not
* specified for maxSwap then this parameter is ignored.
*
* @default 60
*/
readonly swappiness?: number;
}
/**
* Linux-specific options that are applied to the container.
*/
export declare class LinuxParameters extends Construct {
/**
* Whether the init process is enabled
*/
protected readonly initProcessEnabled?: boolean;
/**
* The shared memory size (in MiB). Not valid for Fargate launch type
*/
protected readonly sharedMemorySize?: cdk.Size;
/**
* The max swap memory
*/
protected readonly maxSwap?: cdk.Size;
/**
* The swappiness behavior
*/
protected readonly swappiness?: number;
/**
* Device mounts
*/
protected readonly devices: Device[];
/**
* TmpFs mounts
*/
protected readonly tmpfs: Tmpfs[];
/**
* Constructs a new instance of the LinuxParameters class.
*/
constructor(scope: Construct, id: string, props?: LinuxParametersProps);
private validateProps;
/**
* Adds one or more host devices to a container.
*/
addDevices(...device: Device[]): void;
/**
* Specifies the container path, mount options, and size (in MiB) of the tmpfs mount for a container.
*
* Only works with EC2 launch type.
*/
addTmpfs(...tmpfs: Tmpfs[]): void;
/**
* Renders the Linux parameters to the Batch version of this resource,
* which does not have 'capabilities' and requires tmpfs.containerPath to be defined.
*/
renderLinuxParameters(): CfnJobDefinition.LinuxParametersProperty;
}
/**
* A container instance host device.
*/
export interface Device {
/**
* The path inside the container at which to expose the host device.
*
* @default Same path as the host
*/
readonly containerPath?: string;
/**
* The path for the device on the host container instance.
*/
readonly hostPath: string;
/**
* The explicit permissions to provide to the container for the device.
* By default, the container has permissions for read, write, and mknod for the device.
*
* @default Readonly
*/
readonly permissions?: DevicePermission[];
}
/**
* The details of a tmpfs mount for a container.
*/
export interface Tmpfs {
/**
* The absolute file path where the tmpfs volume is to be mounted.
*/
readonly containerPath: string;
/**
* The size (in MiB) of the tmpfs volume.
*/
readonly size: cdk.Size;
/**
* The list of tmpfs volume mount options. For more information, see
* [TmpfsMountOptions](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Tmpfs.html).
*
* @default none
*/
readonly mountOptions?: TmpfsMountOption[];
}
/**
* Permissions for device access
*/
export declare enum DevicePermission {
/**
* Read
*/
READ = "read",
/**
* Write
*/
WRITE = "write",
/**
* Make a node
*/
MKNOD = "mknod"
}
/**
* The supported options for a tmpfs mount for a container.
*/
export declare enum TmpfsMountOption {
DEFAULTS = "defaults",
RO = "ro",
RW = "rw",
SUID = "suid",
NOSUID = "nosuid",
DEV = "dev",
NODEV = "nodev",
EXEC = "exec",
NOEXEC = "noexec",
SYNC = "sync",
ASYNC = "async",
DIRSYNC = "dirsync",
REMOUNT = "remount",
MAND = "mand",
NOMAND = "nomand",
ATIME = "atime",
NOATIME = "noatime",
DIRATIME = "diratime",
NODIRATIME = "nodiratime",
BIND = "bind",
RBIND = "rbind",
UNBINDABLE = "unbindable",
RUNBINDABLE = "runbindable",
PRIVATE = "private",
RPRIVATE = "rprivate",
SHARED = "shared",
RSHARED = "rshared",
SLAVE = "slave",
RSLAVE = "rslave",
RELATIME = "relatime",
NORELATIME = "norelatime",
STRICTATIME = "strictatime",
NOSTRICTATIME = "nostrictatime",
MODE = "mode",
UID = "uid",
GID = "gid",
NR_INODES = "nr_inodes",
NR_BLOCKS = "nr_blocks",
MPOL = "mpol"
}

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TmpfsMountOption=exports.DevicePermission=exports.LinuxParameters=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},cdk=()=>{var tmp=require("../../core");return cdk=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};class LinuxParameters extends constructs_1().Construct{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_batch.LinuxParameters",version:"2.252.0"};initProcessEnabled;sharedMemorySize;maxSwap;swappiness;devices=new Array;tmpfs=new Array;constructor(scope,id,props={}){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_LinuxParametersProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,LinuxParameters),error}this.validateProps(props),this.sharedMemorySize=props.sharedMemorySize,this.initProcessEnabled=props.initProcessEnabled,this.maxSwap=props.maxSwap,this.swappiness=props.maxSwap?props.swappiness:void 0}validateProps(props){if(!cdk().Token.isUnresolved(props.swappiness)&&props.swappiness!==void 0&&(!Number.isInteger(props.swappiness)||props.swappiness<0||props.swappiness>100))throw new(cdk()).ValidationError((0,literal_string_1().lit)`InvalidSwappiness`,`swappiness: Must be an integer between 0 and 100; received ${props.swappiness}.`,this)}addDevices(...device){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_Device(device)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addDevices),error}this.devices.push(...device)}addTmpfs(...tmpfs){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_Tmpfs(tmpfs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addTmpfs),error}this.tmpfs.push(...tmpfs)}renderLinuxParameters(){return{initProcessEnabled:this.initProcessEnabled,sharedMemorySize:this.sharedMemorySize?.toMebibytes(),maxSwap:this.maxSwap?.toMebibytes(),swappiness:this.swappiness,devices:cdk().Lazy.any({produce:()=>this.devices.map(renderDevice)},{omitEmptyArray:!0}),tmpfs:cdk().Lazy.any({produce:()=>this.tmpfs.map(renderTmpfs)},{omitEmptyArray:!0})}}}exports.LinuxParameters=LinuxParameters;var DevicePermission;(function(DevicePermission2){DevicePermission2.READ="read",DevicePermission2.WRITE="write",DevicePermission2.MKNOD="mknod"})(DevicePermission||(exports.DevicePermission=DevicePermission={}));var TmpfsMountOption;(function(TmpfsMountOption2){TmpfsMountOption2.DEFAULTS="defaults",TmpfsMountOption2.RO="ro",TmpfsMountOption2.RW="rw",TmpfsMountOption2.SUID="suid",TmpfsMountOption2.NOSUID="nosuid",TmpfsMountOption2.DEV="dev",TmpfsMountOption2.NODEV="nodev",TmpfsMountOption2.EXEC="exec",TmpfsMountOption2.NOEXEC="noexec",TmpfsMountOption2.SYNC="sync",TmpfsMountOption2.ASYNC="async",TmpfsMountOption2.DIRSYNC="dirsync",TmpfsMountOption2.REMOUNT="remount",TmpfsMountOption2.MAND="mand",TmpfsMountOption2.NOMAND="nomand",TmpfsMountOption2.ATIME="atime",TmpfsMountOption2.NOATIME="noatime",TmpfsMountOption2.DIRATIME="diratime",TmpfsMountOption2.NODIRATIME="nodiratime",TmpfsMountOption2.BIND="bind",TmpfsMountOption2.RBIND="rbind",TmpfsMountOption2.UNBINDABLE="unbindable",TmpfsMountOption2.RUNBINDABLE="runbindable",TmpfsMountOption2.PRIVATE="private",TmpfsMountOption2.RPRIVATE="rprivate",TmpfsMountOption2.SHARED="shared",TmpfsMountOption2.RSHARED="rshared",TmpfsMountOption2.SLAVE="slave",TmpfsMountOption2.RSLAVE="rslave",TmpfsMountOption2.RELATIME="relatime",TmpfsMountOption2.NORELATIME="norelatime",TmpfsMountOption2.STRICTATIME="strictatime",TmpfsMountOption2.NOSTRICTATIME="nostrictatime",TmpfsMountOption2.MODE="mode",TmpfsMountOption2.UID="uid",TmpfsMountOption2.GID="gid",TmpfsMountOption2.NR_INODES="nr_inodes",TmpfsMountOption2.NR_BLOCKS="nr_blocks",TmpfsMountOption2.MPOL="mpol"})(TmpfsMountOption||(exports.TmpfsMountOption=TmpfsMountOption={}));function renderTmpfs(tmpfs){return{containerPath:tmpfs.containerPath,size:tmpfs.size.toMebibytes(),mountOptions:tmpfs.mountOptions}}function renderDevice(device){return{containerPath:device.containerPath,hostPath:device.hostPath,permissions:device.permissions}}

View File

@@ -0,0 +1,885 @@
import type { Construct } from 'constructs';
import type { IComputeEnvironment, ComputeEnvironmentProps } from './compute-environment-base';
import { ComputeEnvironmentBase } from './compute-environment-base';
import * as ec2 from '../../aws-ec2';
import type * as eks from '../../aws-eks';
import * as iam from '../../aws-iam';
import type { Duration, ITaggable } from '../../core';
import { TagManager } from '../../core';
/**
* Represents a Managed ComputeEnvironment. Batch will provision EC2 Instances to
* meet the requirements of the jobs executing in this ComputeEnvironment.
*/
export interface IManagedComputeEnvironment extends IComputeEnvironment, ec2.IConnectable, ITaggable {
/**
* The maximum vCpus this `ManagedComputeEnvironment` can scale up to.
*
* *Note*: if this Compute Environment uses EC2 resources (not Fargate) with either `AllocationStrategy.BEST_FIT_PROGRESSIVE` or
* `AllocationStrategy.SPOT_CAPACITY_OPTIMIZED`, or `AllocationStrategy.BEST_FIT` with Spot instances,
* The scheduler may exceed this number by at most one of the instances specified in `instanceTypes`
* or `instanceClasses`.
*/
readonly maxvCpus: number;
/**
* Specifies whether this Compute Environment is replaced if an update is made that requires
* replacing its instances. To enable more properties to be updated,
* set this property to `false`. When changing the value of this property to false,
* do not change any other properties at the same time.
* If other properties are changed at the same time,
* and the change needs to be rolled back but it can't,
* it's possible for the stack to go into the UPDATE_ROLLBACK_FAILED state.
* You can't update a stack that is in the UPDATE_ROLLBACK_FAILED state.
* However, if you can continue to roll it back,
* you can return the stack to its original settings and then try to update it again.
*
* The properties which require a replacement of the Compute Environment are:
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-batch-computeenvironment.html#cfn-batch-computeenvironment-replacecomputeenvironment
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-continueupdaterollback.html
*/
readonly replaceComputeEnvironment?: boolean;
/**
* Whether or not to use spot instances.
* Spot instances are less expensive EC2 instances that can be
* reclaimed by EC2 at any time; your job will be given two minutes
* of notice before reclamation.
*
* @default false
*/
readonly spot?: boolean;
/**
* Only meaningful if `terminateOnUpdate` is `false`. If so,
* when an infrastructure update is triggered, any running jobs
* will be allowed to run until `updateTimeout` has expired.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/updating-compute-environments.html
* @default 30 minutes
*/
readonly updateTimeout?: Duration;
/**
* Whether or not any running jobs will be immediately terminated when an infrastructure update
* occurs. If this is enabled, any terminated jobs may be retried, depending on the job's
* retry policy.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/updating-compute-environments.html
*
* @default false
*/
readonly terminateOnUpdate?: boolean;
/**
* The security groups this Compute Environment will launch instances in.
*/
readonly securityGroups: ec2.ISecurityGroup[];
/**
* The VPC Subnets this Compute Environment will launch instances in.
*/
readonly vpcSubnets?: ec2.SubnetSelection;
/**
* Whether or not the AMI is updated to the latest one supported by Batch
* when an infrastructure update occurs.
*
* If you specify a specific AMI, this property will be ignored.
*
* Note: the CDK will never set this value by default, `false` will set by CFN.
* This is to avoid a deployment failure that occurs when this value is set.
*
* @see https://github.com/aws/aws-cdk/issues/27054
*
* @default false
*/
readonly updateToLatestImageVersion?: boolean;
}
/**
* Props for a ManagedComputeEnvironment
*/
export interface ManagedComputeEnvironmentProps extends ComputeEnvironmentProps {
/**
* The maximum vCpus this `ManagedComputeEnvironment` can scale up to.
* Each vCPU is equivalent to 1024 CPU shares.
*
* *Note*: if this Compute Environment uses EC2 resources (not Fargate) with either `AllocationStrategy.BEST_FIT_PROGRESSIVE` or
* `AllocationStrategy.SPOT_CAPACITY_OPTIMIZED`, or `AllocationStrategy.BEST_FIT` with Spot instances,
* The scheduler may exceed this number by at most one of the instances specified in `instanceTypes`
* or `instanceClasses`.
*
* @default 256
*/
readonly maxvCpus?: number;
/**
* Specifies whether this Compute Environment is replaced if an update is made that requires
* replacing its instances. To enable more properties to be updated,
* set this property to `false`. When changing the value of this property to false,
* do not change any other properties at the same time.
* If other properties are changed at the same time,
* and the change needs to be rolled back but it can't,
* it's possible for the stack to go into the UPDATE_ROLLBACK_FAILED state.
* You can't update a stack that is in the UPDATE_ROLLBACK_FAILED state.
* However, if you can continue to roll it back,
* you can return the stack to its original settings and then try to update it again.
*
* The properties which require a replacement of the Compute Environment are:
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-batch-computeenvironment.html#cfn-batch-computeenvironment-replacecomputeenvironment
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-continueupdaterollback.html
*
* @default false
*/
readonly replaceComputeEnvironment?: boolean;
/**
* Whether or not to use spot instances.
* Spot instances are less expensive EC2 instances that can be
* reclaimed by EC2 at any time; your job will be given two minutes
* of notice before reclamation.
*
* @default false
*/
readonly spot?: boolean;
/**
* Only meaningful if `terminateOnUpdate` is `false`. If so,
* when an infrastructure update is triggered, any running jobs
* will be allowed to run until `updateTimeout` has expired.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/updating-compute-environments.html
*
* @default 30 minutes
*/
readonly updateTimeout?: Duration;
/**
* Whether or not any running jobs will be immediately terminated when an infrastructure update
* occurs. If this is enabled, any terminated jobs may be retried, depending on the job's
* retry policy.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/updating-compute-environments.html
*
* @default false
*/
readonly terminateOnUpdate?: boolean;
/**
* VPC in which this Compute Environment will launch Instances
*/
readonly vpc: ec2.IVpc;
/**
* The security groups this Compute Environment will launch instances in.
*
* @default new security groups will be created
*/
readonly securityGroups?: ec2.ISecurityGroup[];
/**
* The VPC Subnets this Compute Environment will launch instances in.
*
* @default new subnets will be created
*/
readonly vpcSubnets?: ec2.SubnetSelection;
/**
* Whether or not the AMI is updated to the latest one supported by Batch
* when an infrastructure update occurs.
*
* If you specify a specific AMI, this property will be ignored.
*
* Note: the CDK will never set this value by default, `false` will set by CFN.
* This is to avoid a deployment failure that occurs when this value is set.
*
* @see https://github.com/aws/aws-cdk/issues/27054
*
* @default false
*/
readonly updateToLatestImageVersion?: boolean;
}
/**
* Abstract base class for ManagedComputeEnvironments
* @internal
*/
export declare abstract class ManagedComputeEnvironmentBase extends ComputeEnvironmentBase implements IManagedComputeEnvironment {
readonly maxvCpus: number;
readonly replaceComputeEnvironment?: boolean;
readonly spot?: boolean;
readonly updateTimeout?: Duration;
readonly terminateOnUpdate?: boolean;
readonly securityGroups: ec2.ISecurityGroup[];
readonly updateToLatestImageVersion?: boolean;
readonly tags: TagManager;
readonly connections: ec2.Connections;
constructor(scope: Construct, id: string, props: ManagedComputeEnvironmentProps);
}
/**
* A ManagedComputeEnvironment that uses ECS orchestration on EC2 instances.
*/
export interface IManagedEc2EcsComputeEnvironment extends IManagedComputeEnvironment {
/**
* Configure which AMIs this Compute Environment can launch.
*
* Leave this `undefined` to allow Batch to choose the latest AMIs it supports for each instance that it launches.
*
* @default
* - ECS_AL2 compatible AMI ids for non-GPU instances, ECS_AL2_NVIDIA compatible AMI ids for GPU instances.
* If the '@aws-cdk/aws-batch:defaultToAL2023' feature flag is set, ECS_AL2023 will be used instead of ECS_AL2.
*/
readonly images?: EcsMachineImage[];
/**
* The allocation strategy to use if not enough instances of
* the best fitting instance type can be allocated.
*
* @default - `BEST_FIT_PROGRESSIVE` if not using Spot instances,
* `SPOT_PRICE_CAPACITY_OPTIMIZED` if using Spot instances.
*/
readonly allocationStrategy?: AllocationStrategy;
/**
* The maximum percentage that a Spot Instance price can be when compared with the
* On-Demand price for that instance type before instances are launched.
* For example, if your maximum percentage is 20%, the Spot price must be
* less than 20% of the current On-Demand price for that Instance.
* You always pay the lowest market price and never more than your maximum percentage.
* For most use cases, Batch recommends leaving this field empty.
*
* @default - 100%
*/
readonly spotBidPercentage?: number;
/**
* The service-linked role that Spot Fleet needs to launch instances on your behalf.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/spot_fleet_IAM_role.html
*
* @default - a new Role will be created
*/
readonly spotFleetRole?: iam.IRole;
/**
* The instance types that this Compute Environment can launch.
* Which one is chosen depends on the `AllocationStrategy` used.
*/
readonly instanceTypes: ec2.InstanceType[];
/**
* The instance classes that this Compute Environment can launch.
* Which one is chosen depends on the `AllocationStrategy` used.
* Batch will automatically choose the size.
*/
readonly instanceClasses: ec2.InstanceClass[];
/**
* Whether or not to use batch's optimal instance type.
* The optimal instance type is equivalent to adding the
* C4, M4, and R4 instance classes. You can specify other instance classes
* (of the same architecture) in addition to the optimal instance classes.
*
* @default true
*/
readonly useOptimalInstanceClasses?: boolean;
/**
* The execution Role that instances launched by this Compute Environment will use.
*
* @default - a role will be created
*/
readonly instanceRole?: iam.IRole;
/**
* The Launch Template that this Compute Environment
* will use to provision EC2 Instances.
*
* *Note*: if `securityGroups` is specified on both your
* launch template and this Compute Environment, **the
* `securityGroup`s on the Compute Environment override the
* ones on the launch template.
*
* @default no launch template
*/
readonly launchTemplate?: ec2.ILaunchTemplate;
/**
* The minimum vCPUs that an environment should maintain,
* even if the compute environment is DISABLED.
*
* @default 0
*/
readonly minvCpus?: number;
/**
* The EC2 placement group to associate with your compute resources.
* If you intend to submit multi-node parallel jobs to this Compute Environment,
* you should consider creating a cluster placement group and associate it with your compute resources.
* This keeps your multi-node parallel job on a logical grouping of instances
* within a single Availability Zone with high network flow potential.
*
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html
*
* @default - no placement group
*/
readonly placementGroup?: ec2.IPlacementGroup;
/**
* Add an instance type to this compute environment
*/
addInstanceType(instanceType: ec2.InstanceType): void;
/**
* Add an instance class to this compute environment
*/
addInstanceClass(instanceClass: ec2.InstanceClass): void;
}
/**
* Base interface for containing all information needed to
* configure a MachineImage in Batch
*/
interface MachineImage {
/**
* The machine image to use
*
* @default - chosen by batch
*/
readonly image?: ec2.IMachineImage;
}
/**
* A Batch MachineImage that is compatible with ECS
*/
export interface EcsMachineImage extends MachineImage {
/**
* Tells Batch which instance type to launch this image on
*
* @default - 'ECS_AL2' for non-gpu instances, 'ECS_AL2_NVIDIA' for gpu instances.
* If the '@aws-cdk/aws-batch:defaultToAL2023' feature flag is set, 'ECS_AL2023' will be used instead of 'ECS_AL2'.
*/
readonly imageType?: EcsMachineImageType;
}
/**
* A Batch MachineImage that is compatible with EKS
*/
export interface EksMachineImage extends MachineImage {
/**
* Tells Batch which instance type to launch this image on
*
* @default - 'EKS_AL2' for non-gpu instances, 'EKS_AL2_NVIDIA' for gpu instances.
* If the '@aws-cdk/aws-batch:defaultToAL2023' feature flag is set, 'EKS_AL2023' will be used instead of 'EKS_AL2'.
*/
readonly imageType?: EksMachineImageType;
}
/**
* Maps the image to instance types
*/
export declare enum EcsMachineImageType {
/**
* Tells Batch that this machine image runs on non-GPU AL2 instances
*/
ECS_AL2 = "ECS_AL2",
/**
* Tells Batch that this machine image runs on non-GPU AL2023 instances.
* Amazon Linux 2023 does not support A1 instances.
*/
ECS_AL2023 = "ECS_AL2023",
/**
* Tells Batch that this machine image runs on GPU instances
*/
ECS_AL2_NVIDIA = "ECS_AL2_NVIDIA",
/**
* Tells Batch that this machine image runs on GPU AL2023 instances
*/
ECS_AL2023_NVIDIA = "ECS_AL2023_NVIDIA"
}
/**
* Maps the image to instance types
*/
export declare enum EksMachineImageType {
/**
* Tells Batch that this machine image runs on non-GPU instances
*/
EKS_AL2 = "EKS_AL2",
/**
* Tells Batch that this machine image runs on GPU instances
*/
EKS_AL2_NVIDIA = "EKS_AL2_NVIDIA",
/**
* Tells Batch that this machine image runs on non-GPU AL2023 instances
*/
EKS_AL2023 = "EKS_AL2023",
/**
* Tells Batch that this machine image runs on GPU AL2023 instances
*/
EKS_AL2023_NVIDIA = "EKS_AL2023_NVIDIA"
}
/**
* Determines how this compute environment chooses instances to spawn
*
* @see https://aws.amazon.com/blogs/compute/optimizing-for-cost-availability-and-throughput-by-selecting-your-aws-batch-allocation-strategy/
*/
export declare enum AllocationStrategy {
/**
* Batch chooses the lowest-cost instance type that fits all the jobs in the queue.
* If instances of that type are not available, the queue will not choose a new type;
* instead, it will wait for the instance to become available.
* This can stall your `Queue`, with your compute environment only using part of its max capacity
* (or none at all) until the `BEST_FIT` instance becomes available.
* This allocation strategy keeps costs lower but can limit scaling.
* `BEST_FIT` isn't supported when updating compute environments
*/
BEST_FIT = "BEST_FIT",
/**
* This is the default Allocation Strategy if `spot` is `false` or unspecified.
* This strategy will examine the Jobs in the queue and choose whichever instance type meets the requirements
* of the jobs in the queue and with the lowest cost per vCPU, just as `BEST_FIT`.
* However, if not all of the capacity can be filled with this instance type,
* it will choose a new next-best instance type to run any jobs that couldnt fit into the `BEST_FIT` capacity.
* To make the most use of this allocation strategy,
* it is recommended to use as many instance classes as is feasible for your workload.
*/
BEST_FIT_PROGRESSIVE = "BEST_FIT_PROGRESSIVE",
/**
* If your workflow tolerates interruptions, you should enable `spot` on your `ComputeEnvironment`
* and use `SPOT_CAPACITY_OPTIMIZED`.
* This will tell Batch to choose the instance types from the ones you've specified that have
* the most spot capacity available to minimize the chance of interruption.
* To get the most benefit from your spot instances,
* you should allow Batch to choose from as many different instance types as possible.
*/
SPOT_CAPACITY_OPTIMIZED = "SPOT_CAPACITY_OPTIMIZED",
/**
* The price and capacity optimized allocation strategy looks at both price and capacity
* to select the Spot Instance pools that are the least likely to be interrupted
* and have the lowest possible price.
*
* The Batch team recommends this over `SPOT_CAPACITY_OPTIMIZED` in most instances.
*/
SPOT_PRICE_CAPACITY_OPTIMIZED = "SPOT_PRICE_CAPACITY_OPTIMIZED"
}
/**
* Batch default instances types
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/instance-type-compute-table.html
*/
export declare enum DefaultInstanceClass {
/**
* x86 based instance types (from the m6i, c6i, r6i, and c7i instance families)
*/
X86_64 = "default_x86_64",
/**
* ARM64 based instance types (from the m6g, c6g, r6g, and c7g instance families)
*/
ARM64 = "default_arm64"
}
/**
* Props for a ManagedEc2ComputeEnvironment
*/
export interface ManagedEc2ComputeEnvironmentProps extends ManagedComputeEnvironmentProps {
/**
* The instance types that this Compute Environment can launch.
* Which one is chosen depends on the `AllocationStrategy` used.
*
* @default - the instances Batch considers will be used (currently C4, M4, and R4)
*/
readonly instanceTypes?: ec2.InstanceType[];
/**
* The instance classes that this Compute Environment can launch.
* Which one is chosen depends on the `AllocationStrategy` used.
* Batch will automatically choose the instance size.
*
* @default - the instances Batch considers will be used (currently C4, M4, and R4)
*/
readonly instanceClasses?: ec2.InstanceClass[];
}
/**
* Props for a ManagedEc2EcsComputeEnvironment
*/
export interface ManagedEc2EcsComputeEnvironmentProps extends ManagedEc2ComputeEnvironmentProps {
/**
* Use batch's default instance types.
* A simpler way to choose up-to-date instance classes based on region
* instead of specifying exact instance classes.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/instance-type-compute-table.html
* @default - choose from instanceTypes and instanceClasses
*/
readonly defaultInstanceClasses?: DefaultInstanceClass[];
/**
* Whether or not to use batch's optimal instance type.
* The optimal instance type is equivalent to adding the
* C4, M4, and R4 instance classes. You can specify other instance classes
* (of the same architecture) in addition to the optimal instance classes.
*
* @default true
*/
readonly useOptimalInstanceClasses?: boolean;
/**
* Configure which AMIs this Compute Environment can launch.
* If you specify this property with only `image` specified, then the
* `imageType` will default to `ECS_AL2` (or `ECS_AL2023` if the
* `@aws-cdk/aws-batch:defaultToAL2023` feature flag is set).
* *If your image needs GPU resources,
* specify `ECS_AL2_NVIDIA` or `ECS_AL2023_NVIDIA`; otherwise, the instances
* will not be able to properly join the ComputeEnvironment*.
*
* @default
* - ECS_AL2 for non-GPU instances, ECS_AL2_NVIDIA for GPU instances.
* If the '@aws-cdk/aws-batch:defaultToAL2023' feature flag is set, ECS_AL2023 will be used instead of ECS_AL2.
*/
readonly images?: EcsMachineImage[];
/**
* The allocation strategy to use if not enough instances of
* the best fitting instance type can be allocated.
*
* @default - `BEST_FIT_PROGRESSIVE` if not using Spot instances,
* `SPOT_PRICE_CAPACITY_OPTIMIZED` if using Spot instances.
*/
readonly allocationStrategy?: AllocationStrategy;
/**
* The maximum percentage that a Spot Instance price can be when compared with the
* On-Demand price for that instance type before instances are launched.
* For example, if your maximum percentage is 20%, the Spot price must be
* less than 20% of the current On-Demand price for that Instance.
* You always pay the lowest market price and never more than your maximum percentage.
* For most use cases, Batch recommends leaving this field empty.
*
* Implies `spot == true` if set
*
* @default 100%
*/
readonly spotBidPercentage?: number;
/**
* The service-linked role that Spot Fleet needs to launch instances on your behalf.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/spot_fleet_IAM_role.html
*
* @default - a new role will be created
*/
readonly spotFleetRole?: iam.IRole;
/**
* The execution Role that instances launched by this Compute Environment will use.
*
* @default - a role will be created
*/
readonly instanceRole?: iam.IRole;
/**
* The Launch Template that this Compute Environment
* will use to provision EC2 Instances.
*
* *Note*: if `securityGroups` is specified on both your
* launch template and this Compute Environment, **the
* `securityGroup`s on the Compute Environment override the
* ones on the launch template.
*
* @default no launch template
*/
readonly launchTemplate?: ec2.ILaunchTemplate;
/**
* The minimum vCPUs that an environment should maintain,
* even if the compute environment is DISABLED.
*
* @default 0
*/
readonly minvCpus?: number;
/**
* The EC2 placement group to associate with your compute resources.
* If you intend to submit multi-node parallel jobs to this Compute Environment,
* you should consider creating a cluster placement group and associate it with your compute resources.
* This keeps your multi-node parallel job on a logical grouping of instances
* within a single Availability Zone with high network flow potential.
*
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html
*
* @default - no placement group
*/
readonly placementGroup?: ec2.IPlacementGroupRef;
}
/**
* A ManagedComputeEnvironment that uses EC2 instances.
*/
interface IManagedEc2ComputeEnvironment extends IManagedComputeEnvironment {
/**
* The instance types that this Compute Environment can launch.
* Which one is chosen depends on the `AllocationStrategy` used.
*/
readonly instanceTypes: ec2.InstanceType[];
/**
* The instance classes that this Compute Environment can launch.
* Which one is chosen depends on the `AllocationStrategy` used.
*/
readonly instanceClasses: ec2.InstanceClass[];
/**
* Add an instance type to this compute environment
*/
addInstanceType(instanceType: ec2.InstanceType): void;
/**
* Add an instance class to this compute environment
*/
addInstanceClass(instanceClass: ec2.InstanceClass): void;
}
/**
* A ManagedComputeEnvironment that uses EC2 instances.
*
*/
declare abstract class ManagedEc2ComputeEnvironment extends ManagedComputeEnvironmentBase implements IManagedEc2ComputeEnvironment {
readonly instanceTypes: ec2.InstanceType[];
readonly instanceClasses: ec2.InstanceClass[];
constructor(scope: Construct, id: string, props: ManagedEc2ComputeEnvironmentProps);
addInstanceType(instanceType: ec2.InstanceType): void;
addInstanceClass(instanceClass: ec2.InstanceClass): void;
}
/**
* A ManagedComputeEnvironment that uses ECS orchestration on EC2 instances.
*
* @resource AWS::Batch::ComputeEnvironment
*/
export declare class ManagedEc2EcsComputeEnvironment extends ManagedEc2ComputeEnvironment implements IManagedEc2EcsComputeEnvironment {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* refer to an existing ComputeEnvironment by its arn.
*/
static fromManagedEc2EcsComputeEnvironmentArn(scope: Construct, id: string, managedEc2EcsComputeEnvironmentArn: string): IManagedEc2EcsComputeEnvironment;
private readonly resource;
get computeEnvironmentArn(): string;
get computeEnvironmentName(): string;
readonly images?: EcsMachineImage[];
readonly allocationStrategy?: AllocationStrategy;
readonly spotBidPercentage?: number;
readonly spotFleetRole?: iam.IRole;
readonly instanceRole?: iam.IRole;
readonly launchTemplate?: ec2.ILaunchTemplate;
readonly minvCpus?: number;
private readonly _placementGroup?;
private readonly instanceProfile;
constructor(scope: Construct, id: string, props: ManagedEc2EcsComputeEnvironmentProps);
get placementGroup(): ec2.IPlacementGroup | undefined;
}
/**
* A ManagedComputeEnvironment that uses EKS orchestration on EC2 instances.
*/
interface IManagedEc2EksComputeEnvironment extends IManagedEc2ComputeEnvironment {
/**
* The namespace of the Cluster
*
* Cannot be 'default', start with 'kube-', or be longer than 64 characters.
*
* @see https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
*/
readonly kubernetesNamespace?: string;
/**
* The cluster that backs this Compute Environment. Required
* for Compute Environments running Kubernetes jobs.
*
* Please ensure that you have followed the steps at
*
* https://docs.aws.amazon.com/batch/latest/userguide/getting-started-eks.html
*
* before attempting to deploy a `ManagedEc2EksComputeEnvironment` that uses this cluster.
* If you do not follow the steps in the link, the deployment fail with a message that the
* compute environment did not stabilize.
*/
readonly eksCluster: eks.ICluster;
/**
* Configure which AMIs this Compute Environment can launch.
*
* @default
* EKS_AL2 for non-GPU instances, EKS_AL2_NVIDIA for GPU instances.
* If the '@aws-cdk/aws-batch:defaultToAL2023' feature flag is set, EKS_AL2023 will be used instead of EKS_AL2.
*/
readonly images?: EksMachineImage[];
/**
* The allocation strategy to use if not enough instances of
* the best fitting instance type can be allocated.
*
* @default - `BEST_FIT_PROGRESSIVE` if not using Spot instances,
* `SPOT_PRICE_CAPACITY_OPTIMIZED` if using Spot instances.
*/
readonly allocationStrategy?: AllocationStrategy;
/**
* The maximum percentage that a Spot Instance price can be when compared with the
* On-Demand price for that instance type before instances are launched.
* For example, if your maximum percentage is 20%, the Spot price must be
* less than 20% of the current On-Demand price for that Instance.
* You always pay the lowest market price and never more than your maximum percentage.
* For most use cases, Batch recommends leaving this field empty.
*
* Implies `spot == true` if set
*
* @default - 100%
*/
readonly spotBidPercentage?: number;
/**
* The execution Role that instances launched by this Compute Environment will use.
*
* @default - a role will be created
*/
readonly instanceRole?: iam.IRole;
/**
* The Launch Template that this Compute Environment
* will use to provision EC2 Instances.
*
* *Note*: if `securityGroups` is specified on both your
* launch template and this Compute Environment, **the
* `securityGroup`s on the Compute Environment override the
* ones on the launch template.
*
* @default - no launch template
*/
readonly launchTemplate?: ec2.ILaunchTemplate;
/**
* The minimum vCPUs that an environment should maintain,
* even if the compute environment is DISABLED.
*
* @default 0
*/
readonly minvCpus?: number;
/**
* The EC2 placement group to associate with your compute resources.
* If you intend to submit multi-node parallel jobs to this Compute Environment,
* you should consider creating a cluster placement group and associate it with your compute resources.
* This keeps your multi-node parallel job on a logical grouping of instances
* within a single Availability Zone with high network flow potential.
*
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html
*
* @default - no placement group
*/
readonly placementGroup?: ec2.IPlacementGroup;
}
/**
* Props for a ManagedEc2EksComputeEnvironment
*/
export interface ManagedEc2EksComputeEnvironmentProps extends ManagedEc2ComputeEnvironmentProps {
/**
* The namespace of the Cluster
*/
readonly kubernetesNamespace: string;
/**
* The cluster that backs this Compute Environment. Required
* for Compute Environments running Kubernetes jobs.
*
* Please ensure that you have followed the steps at
*
* https://docs.aws.amazon.com/batch/latest/userguide/getting-started-eks.html
*
* before attempting to deploy a `ManagedEc2EksComputeEnvironment` that uses this cluster.
* If you do not follow the steps in the link, the deployment fail with a message that the
* compute environment did not stabilize.
*/
readonly eksCluster: eks.ICluster;
/**
* Use batch's default instance types.
* A simpler way to choose up-to-date instance classes based on region
* instead of specifying exact instance classes.
*
* @see https://docs.aws.amazon.com/batch/latest/userguide/instance-type-compute-table.html
* @default - choose from instanceTypes and instanceClasses
*/
readonly defaultInstanceClasses?: DefaultInstanceClass[];
/**
* Whether or not to use batch's optimal instance type.
* The optimal instance type is equivalent to adding the
* C4, M4, and R4 instance classes. You can specify other instance classes
* (of the same architecture) in addition to the optimal instance classes.
*
* @default true
*/
readonly useOptimalInstanceClasses?: boolean;
/**
* Configure which AMIs this Compute Environment can launch.
*
* @default
* If `imageKubernetesVersion` is specified,
* - EKS_AL2 for non-GPU instances, EKS_AL2_NVIDIA for GPU instances.
* Otherwise,
* - ECS_AL2 for non-GPU instances, ECS_AL2_NVIDIA for GPU instances.
* If the '@aws-cdk/aws-batch:defaultToAL2023' feature flag is set, EKS_AL2023 / ECS_AL2023 will be used instead.
*/
readonly images?: EksMachineImage[];
/**
* The allocation strategy to use if not enough instances of
* the best fitting instance type can be allocated.
*
* @default - `BEST_FIT_PROGRESSIVE` if not using Spot instances,
* `SPOT_PRICE_CAPACITY_OPTIMIZED` if using Spot instances.
*/
readonly allocationStrategy?: AllocationStrategy;
/**
* The maximum percentage that a Spot Instance price can be when compared with the
* On-Demand price for that instance type before instances are launched.
* For example, if your maximum percentage is 20%, the Spot price must be
* less than 20% of the current On-Demand price for that Instance.
* You always pay the lowest market price and never more than your maximum percentage.
* For most use cases, Batch recommends leaving this field empty.
*
* Implies `spot == true` if set
*
* @default - 100%
*/
readonly spotBidPercentage?: number;
/**
* The execution Role that instances launched by this Compute Environment will use.
*
* @default - a role will be created
*/
readonly instanceRole?: iam.IRole;
/**
* The Launch Template that this Compute Environment
* will use to provision EC2 Instances.
*
* *Note*: if `securityGroups` is specified on both your
* launch template and this Compute Environment, **the
* `securityGroup`s on the Compute Environment override the
* ones on the launch template.**
*
* @default - no launch template
*/
readonly launchTemplate?: ec2.ILaunchTemplate;
/**
* The minimum vCPUs that an environment should maintain,
* even if the compute environment is DISABLED.
*
* @default 0
*/
readonly minvCpus?: number;
/**
* The EC2 placement group to associate with your compute resources.
* If you intend to submit multi-node parallel jobs to this Compute Environment,
* you should consider creating a cluster placement group and associate it with your compute resources.
* This keeps your multi-node parallel job on a logical grouping of instances
* within a single Availability Zone with high network flow potential.
*
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html
*
* @default - no placement group
*/
readonly placementGroup?: ec2.IPlacementGroupRef;
}
/**
* A ManagedComputeEnvironment that uses ECS orchestration on EC2 instances.
*
* @resource AWS::Batch::ComputeEnvironment
*/
export declare class ManagedEc2EksComputeEnvironment extends ManagedEc2ComputeEnvironment implements IManagedEc2EksComputeEnvironment {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
readonly kubernetesNamespace?: string;
readonly eksCluster: eks.ICluster;
private readonly resource;
get computeEnvironmentName(): string;
get computeEnvironmentArn(): string;
readonly images?: EksMachineImage[];
readonly allocationStrategy?: AllocationStrategy;
readonly spotBidPercentage?: number;
readonly instanceRole?: iam.IRole;
readonly launchTemplate?: ec2.ILaunchTemplate;
readonly minvCpus?: number;
private readonly _placementGroup?;
private readonly instanceProfile;
constructor(scope: Construct, id: string, props: ManagedEc2EksComputeEnvironmentProps);
get placementGroup(): ec2.IPlacementGroup | undefined;
}
/**
* A ManagedComputeEnvironment that uses ECS orchestration on Fargate instances.
*/
export interface IFargateComputeEnvironment extends IManagedComputeEnvironment {
}
/**
* Props for a FargateComputeEnvironment
*/
export interface FargateComputeEnvironmentProps extends ManagedComputeEnvironmentProps {
}
/**
* A ManagedComputeEnvironment that uses ECS orchestration on Fargate instances.
*
* @resource AWS::Batch::ComputeEnvironment
*/
export declare class FargateComputeEnvironment extends ManagedComputeEnvironmentBase implements IFargateComputeEnvironment {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* Reference an existing FargateComputeEnvironment by its arn
*/
static fromFargateComputeEnvironmentArn(scope: Construct, id: string, fargateComputeEnvironmentArn: string): IFargateComputeEnvironment;
private readonly resource;
get computeEnvironmentName(): string;
get computeEnvironmentArn(): string;
constructor(scope: Construct, id: string, props: FargateComputeEnvironmentProps);
}
export {};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,128 @@
import type { Construct } from 'constructs';
import type { IEcsContainerDefinition } from './ecs-container-definition';
import type { IJobDefinition, JobDefinitionProps } from './job-definition-base';
import { JobDefinitionBase } from './job-definition-base';
import * as ec2 from '../../aws-ec2';
/**
* Not a real instance type! Indicates that Batch will choose one it determines to be optimal
* for the workload.
*/
export declare class OptimalInstanceType extends ec2.InstanceType {
constructor();
}
interface IMultiNodeJobDefinition extends IJobDefinition {
/**
* The containers that this multinode job will run.
*
* @see https://aws.amazon.com/blogs/compute/building-a-tightly-coupled-molecular-dynamics-workflow-with-multi-node-parallel-jobs-in-aws-batch/
*/
readonly containers: MultiNodeContainer[];
/**
* The instance type that this job definition will run
*
* @default - optimal instance, selected by Batch
*/
readonly instanceType?: ec2.InstanceType;
/**
* The index of the main node in this job.
* The main node is responsible for orchestration.
*
* @default 0
*/
readonly mainNode?: number;
/**
* Whether to propagate tags from the JobDefinition
* to the ECS task that Batch spawns
*
* @default false
*/
readonly propagateTags?: boolean;
/**
* Add a container to this multinode job
*/
addContainer(container: MultiNodeContainer): void;
}
/**
* Runs the container on nodes [startNode, endNode]
*/
export interface MultiNodeContainer {
/**
* The index of the first node to run this container
*
* The container is run on all nodes in the range [startNode, endNode] (inclusive)
*/
readonly startNode: number;
/**
* The index of the last node to run this container.
*
* The container is run on all nodes in the range [startNode, endNode] (inclusive)
*/
readonly endNode: number;
/**
* The container that this node range will run
*/
readonly container: IEcsContainerDefinition;
}
/**
* Props to configure a MultiNodeJobDefinition
*/
export interface MultiNodeJobDefinitionProps extends JobDefinitionProps {
/**
* The instance type that this job definition
* will run.
*
* @default - optimal instance, selected by Batch
*/
readonly instanceType?: ec2.InstanceType;
/**
* The containers that this multinode job will run.
*
* @see https://aws.amazon.com/blogs/compute/building-a-tightly-coupled-molecular-dynamics-workflow-with-multi-node-parallel-jobs-in-aws-batch/
*
* @default none
*/
readonly containers?: MultiNodeContainer[];
/**
* The index of the main node in this job.
* The main node is responsible for orchestration.
*
* @default 0
*/
readonly mainNode?: number;
/**
* Whether to propagate tags from the JobDefinition
* to the ECS task that Batch spawns
*
* @default false
*/
readonly propagateTags?: boolean;
}
/**
* A JobDefinition that uses Ecs orchestration to run multiple containers
*
* @resource AWS::Batch::JobDefinition
*/
export declare class MultiNodeJobDefinition extends JobDefinitionBase implements IMultiNodeJobDefinition {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* refer to an existing JobDefinition by its arn
*/
static fromJobDefinitionArn(scope: Construct, id: string, jobDefinitionArn: string): IJobDefinition;
readonly mainNode?: number;
readonly propagateTags?: boolean;
private readonly resource;
private _containers;
get containers(): MultiNodeContainer[];
get jobDefinitionArn(): string;
get jobDefinitionName(): string;
private readonly _instanceType?;
constructor(scope: Construct, id: string, props?: MultiNodeJobDefinitionProps);
/**
* If the prop `instanceType` is left `undefined`, then this
* will hold a fake instance type, for backwards compatibility reasons.
*/
get instanceType(): ec2.InstanceType;
addContainer(container: MultiNodeContainer): void;
}
export {};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
import type { ISchedulingPolicyRef } from '../../../interfaces/generated/aws-batch-interfaces.generated';
import type { ISchedulingPolicy } from '../scheduling-policy';
/**
* Converts an ISchedulingPolicyRef to ISchedulingPolicy, validating that it implements the full interface.
*/
export declare function toISchedulingPolicy(policy: ISchedulingPolicyRef): ISchedulingPolicy;

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.toISchedulingPolicy=toISchedulingPolicy;var core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};function toISchedulingPolicy(policy){if(!("schedulingPolicyArn"in policy)||!("schedulingPolicyName"in policy))throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`SchedulingPolicyInstanceImplementScheduling`,`'schedulingPolicy' instance should implement ISchedulingPolicy, but doesn't: ${policy.constructor.name}`);return policy}

View File

@@ -0,0 +1,195 @@
import type { Construct } from 'constructs';
import type { Duration, IResource } from '../../core';
import { Resource } from '../../core';
import type { ISchedulingPolicyRef, SchedulingPolicyReference } from '../../interfaces/generated/aws-batch-interfaces.generated';
/**
* Represents a Scheduling Policy. Scheduling Policies tell the Batch
* Job Scheduler how to schedule incoming jobs.
*/
export interface ISchedulingPolicy extends IResource, ISchedulingPolicyRef {
/**
* The name of this scheduling policy
*
* @attribute
*/
readonly schedulingPolicyName: string;
/**
* The arn of this scheduling policy
*
* @attribute
*/
readonly schedulingPolicyArn: string;
}
/**
* Props to configure a SchedulingPolicy
*/
interface SchedulingPolicyProps {
/**
* The name of this SchedulingPolicy
*
* @default - generated by CloudFormation
*/
readonly schedulingPolicyName?: string;
}
/**
* @internal
*/
export declare abstract class SchedulingPolicyBase extends Resource implements ISchedulingPolicy {
abstract readonly schedulingPolicyName: string;
abstract readonly schedulingPolicyArn: string;
get schedulingPolicyRef(): SchedulingPolicyReference;
constructor(scope: Construct, id: string, props?: SchedulingPolicyProps);
}
/**
* Represents a group of Job Definitions. All Job Definitions that
* declare a share identifier will be considered members of the Share
* defined by that share identifier.
*
* The Scheduler divides the maximum available vCPUs of the ComputeEnvironment
* among Jobs in the Queue based on their shareIdentifier and the weightFactor
* associated with that shareIdentifier.
*/
export interface Share {
/**
* The identifier of this Share. All jobs that specify this share identifier
* when submitted to the queue will be considered as part of this Share.
*/
readonly shareIdentifier: string;
/**
* The weight factor given to this Share. The Scheduler decides which jobs to put in the Compute Environment
* such that the following ratio is equal for each job:
*
* `sharevCpu / weightFactor`,
*
* where `sharevCpu` is the total amount of vCPU given to that particular share; that is,
* the sum of the vCPU of each job currently in the Compute Environment for that share.
*
* See the readme of this module for a detailed example that shows how these are used,
* how it relates to `computeReservation`, and how `shareDecay` affects these calculations.
*/
readonly weightFactor: number;
}
/**
* Represents a Fairshare Scheduling Policy. Instructs the scheduler
* to allocate ComputeEnvironment vCPUs based on Job shareIdentifiers.
*
* The Faireshare Scheduling Policy ensures that each share gets a certain amount of vCPUs.
* It does this by deciding how many Jobs of each share to schedule *relative to how many jobs of
* each share are currently being executed by the ComputeEnvironment*. The weight factors associated with
* each share determine the ratio of vCPUs allocated; see the readme for a more in-depth discussion of
* fairshare policies.
*/
export interface IFairshareSchedulingPolicy extends ISchedulingPolicy {
/**
* Used to calculate the percentage of the maximum available vCPU to reserve for share identifiers not present in the Queue.
*
* The percentage reserved is defined by the Scheduler as:
* `(computeReservation/100)^ActiveFairShares` where `ActiveFairShares` is the number of active fair share identifiers.
*
* For example, a computeReservation value of 50 indicates that AWS Batch reserves 50% of the
* maximum available vCPU if there's only one fair share identifier.
* It reserves 25% if there are two fair share identifiers.
* It reserves 12.5% if there are three fair share identifiers.
*
* A computeReservation value of 25 indicates that AWS Batch should reserve 25% of the
* maximum available vCPU if there's only one fair share identifier,
* 6.25% if there are two fair share identifiers,
* and 1.56% if there are three fair share identifiers.
*
* @default - no vCPU is reserved
*/
readonly computeReservation?: number;
/**
* The amount of time to use to measure the usage of each job.
* The usage is used to calculate a fair share percentage for each fair share identifier currently in the Queue.
* A value of zero (0) indicates that only current usage is measured.
* The decay is linear and gives preference to newer jobs.
*
* The maximum supported value is 604800 seconds (1 week).
*
* @default - 0: only the current job usage is considered
*/
readonly shareDecay?: Duration;
/**
* The shares that this Scheduling Policy applies to.
* *Note*: It is possible to submit Jobs to the queue with Share Identifiers that
* are not recognized by the Scheduling Policy.
*/
readonly shares: Share[];
}
/**
* Fairshare SchedulingPolicy configuration
*/
export interface FairshareSchedulingPolicyProps extends SchedulingPolicyProps {
/**
* Used to calculate the percentage of the maximum available vCPU to reserve for share identifiers not present in the Queue.
*
* The percentage reserved is defined by the Scheduler as:
* `(computeReservation/100)^ActiveFairShares` where `ActiveFairShares` is the number of active fair share identifiers.
*
* For example, a computeReservation value of 50 indicates that AWS Batch reserves 50% of the
* maximum available vCPU if there's only one fair share identifier.
* It reserves 25% if there are two fair share identifiers.
* It reserves 12.5% if there are three fair share identifiers.
*
* A computeReservation value of 25 indicates that AWS Batch should reserve 25% of the
* maximum available vCPU if there's only one fair share identifier,
* 6.25% if there are two fair share identifiers,
* and 1.56% if there are three fair share identifiers.
*
* @default - no vCPU is reserved
*/
readonly computeReservation?: number;
/**
* The amount of time to use to measure the usage of each job.
* The usage is used to calculate a fair share percentage for each fair share identifier currently in the Queue.
* A value of zero (0) indicates that only current usage is measured.
* The decay is linear and gives preference to newer jobs.
*
* The maximum supported value is 604800 seconds (1 week).
*
* @default - 0: only the current job usage is considered
*/
readonly shareDecay?: Duration;
/**
* The shares that this Scheduling Policy applies to.
* *Note*: It is possible to submit Jobs to the queue with Share Identifiers that
* are not recognized by the Scheduling Policy.
*
* @default - no shares
*/
readonly shares?: Share[];
}
/**
* Represents a Fairshare Scheduling Policy. Instructs the scheduler
* to allocate ComputeEnvironment vCPUs based on Job shareIdentifiers.
*
* The Faireshare Scheduling Policy ensures that each share gets a certain amount of vCPUs.
* The scheduler does this by deciding how many Jobs of each share to schedule *relative to how many jobs of
* each share are currently being executed by the ComputeEnvironment*. The weight factors associated with
* each share determine the ratio of vCPUs allocated; see the readme for a more in-depth discussion of
* fairshare policies.
*
* @resource AWS::Batch::SchedulingPolicy
*/
export declare class FairshareSchedulingPolicy extends SchedulingPolicyBase implements IFairshareSchedulingPolicy {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* Reference an existing Scheduling Policy by its ARN
*/
static fromFairshareSchedulingPolicyArn(scope: Construct, id: string, fairshareSchedulingPolicyArn: string): IFairshareSchedulingPolicy;
readonly computeReservation?: number;
readonly shareDecay?: Duration;
private readonly _shares;
private readonly resource;
get schedulingPolicyArn(): string;
get shares(): Share[];
get schedulingPolicyName(): string;
constructor(scope: Construct, id: string, props?: FairshareSchedulingPolicyProps);
/**
* Add a share this to this Fairshare SchedulingPolicy
*/
addShare(share: Share): void;
}
export {};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
import type { Construct } from 'constructs';
import type { IComputeEnvironment, ComputeEnvironmentProps } from './compute-environment-base';
import { ComputeEnvironmentBase } from './compute-environment-base';
/**
* Represents an UnmanagedComputeEnvironment. Batch will not provision instances on your behalf
* in this ComputeEvironment.
*/
export interface IUnmanagedComputeEnvironment extends IComputeEnvironment {
/**
* The vCPUs this Compute Environment provides. Used only by the
* scheduler to schedule jobs in `Queue`s that use `FairshareSchedulingPolicy`s.
*
* **If this parameter is not provided on a fairshare queue, no capacity is reserved**;
* that is, the `FairshareSchedulingPolicy` is ignored.
*/
readonly unmanagedvCPUs?: number;
}
/**
* Represents an UnmanagedComputeEnvironment. Batch will not provision instances on your behalf
* in this ComputeEvironment.
*/
export interface UnmanagedComputeEnvironmentProps extends ComputeEnvironmentProps {
/**
* The vCPUs this Compute Environment provides. Used only by the
* scheduler to schedule jobs in `Queue`s that use `FairshareSchedulingPolicy`s.
*
* **If this parameter is not provided on a fairshare queue, no capacity is reserved**;
* that is, the `FairshareSchedulingPolicy` is ignored.
*
* @default 0
*/
readonly unmanagedvCpus?: number;
}
/**
* Unmanaged ComputeEnvironments do not provision or manage EC2 instances on your behalf.
*
* @resource AWS::Batch::ComputeEnvironment
*/
export declare class UnmanagedComputeEnvironment extends ComputeEnvironmentBase implements IUnmanagedComputeEnvironment {
/** Uniquely identifies this class. */
static readonly PROPERTY_INJECTION_ID: string;
/**
* Import an UnmanagedComputeEnvironment by its arn
*/
static fromUnmanagedComputeEnvironmentArn(scope: Construct, id: string, unmanagedComputeEnvironmentArn: string): IUnmanagedComputeEnvironment;
readonly unmanagedvCPUs?: number | undefined;
private readonly resource;
get computeEnvironmentArn(): string;
get computeEnvironmentName(): string;
constructor(scope: Construct, id: string, props?: UnmanagedComputeEnvironmentProps);
}

File diff suppressed because one or more lines are too long