Ivan Zerin
02/03/2025, 11:15 PMprefect work-pool create --type ecs:push --provision-infra my-ecs-pool
and I'm trying to submit a simple flow with custom docker image (need to use several python packages, but it is not the case). Here is the code:
from prefect import flow, task
from prefect_shell import ShellOperation
from prefect.docker import DockerImage
@flow(log_prints=True)
def my_flow(name: str = "world"):
print(f"Hello {name}! I'm a flow running in a ECS task!")
install_result = test_cli()
print(f"Install result {install_result}")
@task
def test_cli():
return ShellOperation(
commands=[
"echo 'Hello!'",
],
).run()
if __name__ == "__main__":
my_flow.deploy(
name="my-deployment-1",
work_pool_name="aws-ecs-pool",
image=DockerImage(
name="prefect-flows:latest",
platform="linux/amd64",
dockerfile="Dockerfile",
)
)
The issue I have: most times I get an issue during flow execution:
Flow run could not be submitted to infrastructure: TaskFailedToStart - CannotPullContainerError: The task cannot pull <http://629775924176.dkr.ecr.us-east-1.amazonaws.com/prefect-flows:latest|629775924176.dkr.ecr.us-east-1.amazonaws.com/prefect-flows:latest> from the registry <http://629775924176.dkr.ecr.us-east-1.amazonaws.com/prefect-flows:latest|629775924176.dkr.ecr.us-east-1.amazonaws.com/prefect-flows:latest>. There is a connection issue between the task and the registry. Check your task network configuration. : failed to copy: httpReadSeeker: failed open: failed to do request: Get <http://629775924176.dkr.ecr.us-east-1.amazonaws.com/prefect-flows:latest|629775924176.dkr.ecr.us-east-1.amazonaws.com/prefect-flows:latest>: dial tcp 54.231.224.2:443: i/o timeout
Initially I was supposing, not every component was installed by prefect cli for provisioning of infra, however form time to time flow is being executed.
Could advice how I could reach stable prefect job execution on serveless aws infrastructure?Jake Kaplan
02/03/2025, 11:39 PM--provision-infra
command, did use all the defaults to spin up everything fresh or did you pass another existing VPC maybe?Ivan Zerin
02/03/2025, 11:44 PMJake Kaplan
02/03/2025, 11:55 PMJake Kaplan
02/03/2025, 11:56 PMIvan Zerin
02/04/2025, 3:38 PMJake Kaplan
02/04/2025, 3:54 PMnetwork_configuration
where you should be able to specify a single subnet to use:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-awsvpcconfiguration.htmlJake Kaplan
02/04/2025, 3:57 PMimport asyncio
from prefect.infrastructure.provisioners.ecs import VpcResource
async def main():
def mock_advance():
pass
base_job_template = {
"variables": {
"properties": {
"vpc_id": {
"default": "",
},
},
}
}
await VpcResource(
vpc_name=...,
ecs_security_group_name=...,
).provision(base_job_template, mock_advance)
print(base_job_template)
if __name__ == '__main__':
asyncio.run(main())
Jake Kaplan
02/04/2025, 3:59 PMJake Kaplan
02/04/2025, 3:59 PMIvan Zerin
02/04/2025, 3:59 PMOn your work pool there is a setting calledHow should I apply that setting? Via prefect cli?where you should be able to specify a single subnet to use:network_configuration
Jake Kaplan
02/04/2025, 4:01 PMIvan Zerin
02/04/2025, 4:34 PMJake Kaplan
02/04/2025, 4:43 PMJake Kaplan
02/04/2025, 4:44 PMIvan Zerin
02/04/2025, 7:44 PMJake Kaplan
02/04/2025, 7:49 PMIvan Zerin
02/04/2025, 8:45 PMIvan Zerin
02/05/2025, 12:55 PMfrom prefect.infrastructure.provisioners import (
ImportError: cannot import name '_provisioners' from partially initialized module 'prefect.infrastructure.provisioners' (most likely due to a circular import) (/.../rb-prefect-master/venv/lib64/python3.10/site-packages/prefect/infrastructure/provisioners/__init__.py)
@Jake Kaplan any advice how to workaround it?Jake Kaplan
02/05/2025, 2:41 PM--provision-infra
cli command, but first making sure your current vpc is not marked as IsDefault
so it will create a new one
• Trying to figure out what in your existing VPC is leading to network failures if not the subnet issueIvan Zerin
02/07/2025, 10:05 PMJake Kaplan
02/07/2025, 10:40 PM