AWS CDK Batch "Compute Environments must be created and valid before creating a job queue"

Viewed 58

I am having issues with AWS CDK V2 (specifically aws-cdk-lib==2.3.0); when I run cdk deploy I am getting the error MyJobQueue Resource handler returned message: "Compute Environments must be created and valid before creating a job queue

My code looks like (I am not using the L2 constructs as they are experimental)

batch_fargate_spot_compute_environment = batch.CfnComputeEnvironment(
    self,
    f"{NAME}FargateSpotComputeEnvironment",
    type='MANAGED',
    compute_resources=batch.CfnComputeEnvironment.ComputeResourcesProperty(
        type='FARGATE_SPOT',
        maxv_cpus=1000,
        subnets=subnets,
        security_group_ids=[security_group.security_group_id]
    ),
    state="ENABLED",
    service_role=batch_service_role.role_arn,
    compute_environment_name=f"{NAME}FargateSpotComputeEnvironment",
)

job_queue = batch.CfnJobQueue(
    self,
    f"{NAME}JobQueue",
    job_queue_name=f"{NAME}JobQueue",
    compute_environment_order=[batch.CfnJobQueue.ComputeEnvironmentOrderProperty(
        compute_environment=batch_fargate_spot_compute_environment.compute_environment_name,
        order=1
    )],
    priority=999,
)

I am pretty confused as to why in my cloudformation logs, it is trying to create a job queue before the compute environment?

1 Answers

This did the trick,

job_queue.add_depends_on(batch_fargate_spot_compute_environment)
Related