Search code examples
pythonamazon-web-servicesaws-cdkaws-batch

Can't define 'FARGATE' AWS Batch compute environment from CDK


I am trying to define an AWS Batch Compute Environment with type 'FARGATE' from the Python AWS CDK, but it doesn't seem to be available. This is what I have so far:

compute_resources = ComputeResources(
    vpc=vpc,
    minv_cpus=0,
    maxv_cpus=30,
    type=ComputeResourceType.SPOT,
    desiredv_cpus=0,
    vpc_subnets=SubnetSelection(subnets=vpc.private_subnets),
    security_groups=security_groups
)

compute_env = ComputeEnvironment(
    self,
    'ComputeEnvironment',
    managed=True,
    enabled=True,
    compute_resources=compute_resources,
    service_role=batch_service_role
)

I am trying to set type=ComputeResourceType.FARGATE_SPOT, but it doesn't seem available. Is the only way to do this via CfnComputeEnvironment?

EDIT:

As per the AWS Batch docs, I would expect FARGATE_SPOT to be available as a ComputeResourceType, but it's not.

AWS Batch docs:

enter image description here

AWS CDK API:

Image of ComputeResourceType AWS CDK Docs


Solution

  • ComputeEnvironment is Level 2 construct (high level) and as you pointed out it does not support Fargate. But if you go to Level 1 construct CfnComputeEnvironment you can do this.

    The reason is that it directly maps to CloudFormation's AWS::Batch::ComputeEnvironment which you linked in your question.