<@ULVA73B9P> when I supply my own ecs task definit...
# ask-marvin
m
@Marvin when I supply my own ecs task definition for a job is there a way of setting the availability zone that the job will run in?
m
thought for 259.8 seconds
Short answer: yes, but not by setting an “AZ” field directly. In ECS you control availability zone indirectly via subnets (Fargate) or via placement constraints/strategies (EC2). Prefect will still call ECS RunTask when you supply your own task definition, so you set these on the work pool’s base job template or per-deployment job_variables. Assuming Prefect 3.x: - Fargate: pick subnets that live only in the AZ you want. ECS will place the task in one of the provided subnets. - EC2: you can either restrict subnets (if using awsvpc) and/or add placementConstraints and placementStrategy to pin or influence AZ. Examples you can drop into your ECS work pool’s Base job template (or deployment job_variables): Fargate – pin to a single AZ by choosing only subnets from that AZ
Copy code
{
  "cluster": "your-ecs-cluster",
  "taskDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/your-task-def:42",
  "launchType": "FARGATE",
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": ["subnet-0abc123def45"],  # subnet in us-east-1a
      "securityGroups": ["sg-0123abc456"],
      "assignPublicIp": "ENABLED"
    }
  }
}
EC2 – constrain to one AZ and (optionally) spread when you allow more than one
Copy code
{
  "cluster": "your-ecs-cluster",
  "taskDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/your-task-def:42",
  "capacityProviderStrategy": [{ "capacityProvider": "EC2", "weight": 1 }],
  "placementConstraints": [
    { "type": "memberOf", "expression": "attribute:ecs.availability-zone == us-east-1a" }
  ],
  "placementStrategy": [
    { "type": "spread", "field": "attribute:ecs.availability-zone" }
  ],
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": ["subnet-0abc123def45"],  # optional: restrict to AZ via subnets too
      "securityGroups": ["sg-0123abc456"],
      "assignPublicIp": "DISABLED"
    }
  }
}
Notes: - There is no direct RunTask parameter called “availabilityZone”; ECS chooses AZ based on your subnets (Fargate) or instance placement rules (EC2). - If you provide multiple subnets across different AZs, ECS may place the task in any of those AZs. - For Fargate, placement constraints/strategies are not supported—use subnets only. - If your custom task definition uses networkMode other than awsvpc (EC2 only), subnets won’t apply; rely on placement constraints/strategies. Docs for reference: - Prefect 3 ECS guide: ECS with Prefect 3 - Job variables customization: Customize job variables - AWS RunTask API: RunTask - ECS task placement: Task placement Quick sanity check: are you running on Fargate or EC2 capacity provider, and are you setting these values on the work pool base job template or per-deployment job variables? If you share your current template, I can suggest the exact edits.