Hi everyone, <https://docs.prefect.io/v3/how-to-g...
# ask-community
f
Hi everyone, https://docs.prefect.io/v3/how-to-guides/deployment_infra/serverless Is this not available on open source? I am a bit confused here, trying to deploy on aws serverless but i can't really follow the docs, im getting to
prefect cloud
stuff somehow?
j
Hi! Sorry about that. I'd take a look here: https://docs.prefect.io/v3/concepts/work-pools#work-pools
You can submit to AWS ECS hosting your own worker, which is compatible with open source. Prefect Cloud has the option to host the worker for you (a push work pool)
f
Thanks, i kept going back between those links already. Here is what is not clear to me: • Deploy manually doc: start talking about Event monitoring, SQS stuff which i could not find other info about to understand what that exactly does. Then the confusion with worker and worker pools. Also it was not clear how to assing s3 as the artifact storage for prefect to use it. I kind wanted to have a single page that walks through every step one by one to do it. Also, is there no way to provide this configuration in terraform? Finally, afaik, OSS only supports long running worker processes but how does that scale with the workload? Is that what my flow code runs? Thanks for the support!
Then there is this guide: https://docs.prefect.io/v3/advanced/self-hosted Which starts talking about redis, nginx proxy and so on. Does prefect need redis or not? What is needed and what is optional isn't super clear to me as of now. Doing a try and fail approach to figure it out
j
Sorry this is unclear! Thanks for the feedback. Hopefully I can help clear some things up here: There are actually 3 pieces of infrastructure to think about here: • the Prefect Server • the Worker • the Execution Environment (like ECS) The server is the control plane - it stores all your flow metadata, schedules, run states, etc. You can totally self-host it. Just run
prefect server start
and you get everything out of the box, including a SQLite database. You only need to worry about Postgres, Redis, nginx, etc. when you're scaling out - like if you need multiple API instances or high availability. You can add those pieces incrementally as needed. (or just use Prefect Cloud and we handle all that for you) Now for running your flows on ECS - you need a Worker. The worker is a lightweight process that polls the Prefect API looking for runs in its work pool, then deploys them to ECS on your behalf. Important distinction: your code doesn't run on the worker itself. The worker just orchestrates. Your actual flow code runs inside the ECS tasks it spins up. You have two options for the worker: 1. Host it yourself (works with OSS) - just run it on a small EC2 instance or as its own ECS service (that's what deploying manually is about) 2. Use push work pools where we host the worker for you - but that's Prefect Cloud only, and requires Starter tier or above. On the free tier you'd need to use Prefect-managed compute.
f
Thanks, much clear. I have the server up in ecs already and doing the worker spawning other ecs task part now. It's all terraformed for now and i wonder if the work-pool part can be done as well? I have the job template json, is CLI my only option of storing this? I wonder if this can be done on terraform somehow?
j
Theres a prefect terraform provider that I believe you can use to manage the work pool itself: https://github.com/PrefectHQ/terraform-provider-prefect
f
It's also fine if i can define it in a yaml or git versioned file. Just need to make sure worker job has the correct envs setup and it's quite big so it needs to be git versioned šŸ˜„
https://registry.terraform.io/providers/PrefectHQ/prefect/latest/docs/resources/work_pool I saw that one but how this resource is connected to ecs job template i dont know šŸ¤”
or does it magically work if i just add that resource? šŸ˜„
j
You'll need to manage all that via the
base_job_template
independently, but you can pass that file to the resource so it's deployed automatically (you can do this from the CLI as well in like a github action like you said)
f
Thanks, do you guys provide a docker image for worker as well? It looks like i need to build one, right?
j
f
Thanks, i see now workers submitting runs to ecs and task definition being created but one issue i see here is that after submission run is in pending state but something else went wrong in the infra (container cannot be pulled or task exited and so on). Right now UI provides no visibility on this. Is that expected? I was under the impression that SQS+Eventbridge setup was for this case so workers know about it or am i missing something here?
j
Yes that's right, if the ECS task run fails the worker should pick it from SQS and crash the flow. It's hard to say without looking at the pieces. Are you seeing messages flow through SQS?
f
yes, sqs works. I guess this was an edge case since the flow task was not able to start to even fail. I am adding the zombie flow detection automation to help detect cases which i assume it's made for that case šŸ˜„