# AllocationStrategy

Determines how this compute environment chooses instances to spawn.

- Source: [`aws-batch/lib/managed-compute-environment.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts#L464)
- Type last changed: v2.96.0 · 13 Sep 2023

## Example

TypeScript:

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

const computeEnv = new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', {
  vpc,
  allocationStrategy: batch.AllocationStrategy.BEST_FIT,
});
```

Python:

```python
# vpc: ec2.IVpc

compute_env = batch.ManagedEc2EcsComputeEnvironment(self, "myEc2ComputeEnv",
    vpc=vpc,
    allocation_strategy=batch.AllocationStrategy.BEST_FIT
)
```

Java:

```java
IVpc vpc;

ManagedEc2EcsComputeEnvironment computeEnv = ManagedEc2EcsComputeEnvironment.Builder.create(this, "myEc2ComputeEnv")
        .vpc(vpc)
        .allocationStrategy(AllocationStrategy.BEST_FIT)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
IVpc vpc;

var computeEnv = new ManagedEc2EcsComputeEnvironment(this, "myEc2ComputeEnv", new ManagedEc2EcsComputeEnvironmentProps {
    Vpc = vpc,
    AllocationStrategy = AllocationStrategy.BEST_FIT
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc IVpc

computeEnv := batch.NewManagedEc2EcsComputeEnvironment(this, jsii.String("myEc2ComputeEnv"), &ManagedEc2EcsComputeEnvironmentProps{
	Vpc: Vpc,
	AllocationStrategy: batch.AllocationStrategy_BEST_FIT,
})
```

## Members

| Member | Description |
| --- | --- |
| `BEST_FIT` | Batch chooses the lowest-cost instance type that fits all the jobs in the queue. |
| `BEST_FIT_PROGRESSIVE` | This is the default Allocation Strategy if `spot` is `false` or unspecified. |
| `SPOT_CAPACITY_OPTIMIZED` | If your workflow tolerates interruptions, you should enable `spot` on your `ComputeEnvironment` and use `SPOT_CAPACITY_OPTIMIZED`. |
| `SPOT_PRICE_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. |

## Referenced by

- [`IManagedEc2EcsComputeEnvironment`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_batch.IManagedEc2EcsComputeEnvironment.html).allocationStrategy
- [`ManagedEc2EcsComputeEnvironment`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_batch.ManagedEc2EcsComputeEnvironment.html).allocationStrategy
- [`ManagedEc2EcsComputeEnvironmentProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_batch.ManagedEc2EcsComputeEnvironmentProps.html).allocationStrategy
- [`ManagedEc2EksComputeEnvironment`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_batch.ManagedEc2EksComputeEnvironment.html).allocationStrategy
- [`ManagedEc2EksComputeEnvironmentProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_batch.ManagedEc2EksComputeEnvironmentProps.html).allocationStrategy
