I'm getting CannotPullContainerError when deploying a flow to ECS in a custom VPC

TL;DR: set your custom subnet configuration as part of your run_task_kwargs on ECSRun.

View in #prefect-community on Slack

Jason @Jason: I think I’ve discovered the problem behind my CannotPullContainerError error with regard to launching ECS tasks. I’ve created the prefect-agent service with specific subnets for our data vpc, but the tasks keep getting launched in the default vpc. I’m not sure how to fix this, unless I’m missing an arg in the https://docs.prefect.io/api/latest/run_configs.html#ecsrun task.

Run Configuration | Prefect Docs

Kevin_Kho @Kevin_Kho: You need to supply the vpc in your run_task_kwargs
From another user

import boto3
from prefect import Flow
from prefect.run_configs import ECSRun

flow.run_config = ECSRun(task_definition_arn="arn:aws:ecs:us-west-2:NUMBER:task-definition/xxx:13", labels=["sandbox"], run_task_kwargs=dict(cluster="Data-Engineering", networkConfiguration={
            'awsvpcConfiguration': {
                'subnets': [
                'securityGroups': [
                'assignPublicIp': 'ENABLED'


You can follow that example