Jarrod Brunson
07/10/2025, 1:48 PMMarvin
07/10/2025, 1:48 PMMarvin
07/10/2025, 1:49 PMbash
prefect work-pool create "my-ec2-pool" --type process
2. Create your ECS worker configuration. Save this as `ecs-worker.yaml`:
yaml
version: 1
workPool:
name: "my-ec2-pool"
jobs:
- name: "ecs-fargate-worker"
schedule: null # runs continuously
resource_config:
cpu: 256 # 0.25 vCPU
memory: 512 # MB
ephemeral_storage: 21 # GB
task_role_arn: "arn:aws:iam::<YOUR_AWS_ACCOUNT>:role/prefect-ecs-task-role"
execution_role_arn: "arn:aws:iam::<YOUR_AWS_ACCOUNT>:role/prefect-ecs-execution-role"
cluster: "your-ecs-cluster-name"
vpc_configuration:
subnets:
- "subnet-xxxxx" # Replace with your subnet IDs
security_groups:
- "sg-xxxxx" # Replace with your security group IDs
launch_type: "FARGATE"
platform_version: "LATEST"
assign_public_ip: true # Set to false if using private subnets
3. Deploy the worker:
bash
prefect worker start-job ecs-worker.yaml
Important notes about this configuration:
1. You'll need to replace the following placeholders:
- `<YOUR_AWS_ACCOUNT>`: Your AWS account ID
- `subnet-xxxxx`: Your VPC subnet ID(s)
- `sg-xxxxx`: Your security group ID(s)
- `your-ecs-cluster-name`: Your ECS cluster name
2. The IAM roles (task_role_arn
and execution_role_arn
) need appropriate permissions:
- The task role needs permissions to interact with AWS services your flows will use
- The execution role needs permissions to pull container images and write logs
3. Resource configurations can be adjusted based on your needs:
- `cpu`: Valid values are 256 (.25 vCPU), 512 (.5 vCPU), 1024 (1 vCPU), 2048 (2 vCPU), etc.
- `memory`: Must be appropriate for the CPU value selected
- `ephemeral_storage`: Between 21 and 200 GB
4. The vpc_configuration
is required for Fargate tasks. Ensure your VPC has either:
- Public subnets with assign_public_ip: true
for internet access
- Private subnets with a NAT Gateway and assign_public_ip: false
You can find more detailed configuration options and setup instructions in the Prefect ECS Guide.
Would you like me to elaborate on any part of this configuration or explain how to set up the required IAM roles?Jarrod Brunson
07/10/2025, 1:59 PMMarvin
07/10/2025, 1:59 PMMarvin
07/10/2025, 2:00 PMMarvin
07/10/2025, 2:00 PMlaunchType
directly. Instead, you need to configure a capacity provider strategy. Here's the correct configuration for your base job template:
json
{
"task_run_request": {
"capacityProviderStrategy": [
{
"capacityProvider": "YOUR_CAPACITY_PROVIDER_NAME",
"weight": 1,
"base": 0
}
],
"cluster": "your-ecs-cluster-name",
"networkConfiguration": {
"awsvpcConfiguration": {
"subnets": ["subnet-xxxxx"],
"securityGroups": ["sg-xxxxx"],
"assignPublicIp": "ENABLED" // or "DISABLED" for private subnets
}
},
"taskDefinition": "your-task-definition-arn"
}
}
Key points about this configuration:
1. Remove any launchType
specification - using launchType
will actually override and ignore the capacity provider strategy
2. The capacityProviderStrategy
configuration is required and should include:
- `capacityProvider`: The name of your EC2 capacity provider
- `weight`: Relative weight for the capacity provider (typically 1)
- `base`: Minimum number of tasks to run on the specified provider (typically 0)
3. You'll still need the standard networking configuration:
- subnets
- securityGroups
- assignPublicIp
setting
To create the work pool with this configuration:
bash
prefect work-pool create "my-ec2-pool" \
--type ecs \
--base-job-template path/to/your/template.json
Prerequisites for this to work:
1. An ECS cluster must be set up with EC2 capacity providers
2. An Auto Scaling Group (ASG) must be configured and associated with your capacity provider
3. The appropriate IAM roles and permissions must be in place
Would you like me to provide more details about setting up the prerequisite AWS resources or explain any part of this configuration in more detail?Jarrod Brunson
07/10/2025, 2:11 PMMarvin
07/10/2025, 2:11 PMMarvin
07/10/2025, 2:12 PMlaunchType: "EC2"
versus capacity providers is important. Here's when each should be used:
Use launchType: "EC2"
when:
1. You're using a standalone ECS cluster without auto-scaling groups
2. You have a fixed set of EC2 instances and want direct placement of tasks on them
3. You're not using cluster auto-scaling features
4. You want simple, direct control over where tasks run
Use capacity providers (without specifying launchType) when:
1. You're using Auto Scaling Groups (ASG)
2. You want automatic scaling of EC2 instances based on demand
3. You need mixed capacity types (like spot instances + on-demand)
4. You want ECS to manage the scaling and placement of tasks automatically
In your case, since you mentioned using an EC2 work pool that presumably needs to scale, you should use the capacity provider strategy approach. The launchType: "EC2"
setting would actually prevent the auto-scaling features from working properly because it bypasses the capacity provider configuration.
This is why many users encounter the RESOURCE:CPU
or RESOURCE:MEMORY
errors when using launchType: "EC2"
- the tasks try to launch immediately on existing instances without waiting for the auto-scaling group to provision new capacity.
The capacity provider approach is more flexible and robust, allowing ECS to:
- Scale your EC2 instances automatically
- Wait for capacity to become available
- Handle task placement more intelligently
- Manage mixed instance types if needed
Would you like me to provide an example of how to set up the capacity providers in your ECS cluster?Jarrod Brunson
07/10/2025, 2:16 PMMarvin
07/10/2025, 2:16 PMMarvin
07/10/2025, 2:16 PMcapacityProviderStrategy
parameter, it states:
The capacity provider strategy to use for the task.
If a capacityProviderStrategy is specified, the launchType parameter must be omitted. If no capacityProviderStrategy or launchType is specified, the defaultCapacityProviderStrategy for the cluster is used.Additionally, in the AWS ECS Developer Guide section on Capacity Providers, it explains that when using cluster auto scaling, you must specify capacityProviderStrategy and not launchType. This is a critical distinction that isn't always clearly documented in higher-level tools and frameworks. The behavior I described earlier about task placement and auto-scaling is a direct consequence of this API-level constraint - you can't use both simultaneously, and the presence of a launchType will override and ignore any capacity provider settings. Would you like me to provide more specific documentation links or explain how this impacts your ECS work pool configuration?