Anton L.
08/23/2024, 9:02 PMMarvin
08/23/2024, 9:03 PMshell
prefect work-pool create --type ecs my-ecs-pool
2. Configure the ECS Work Pool:
- Use EC2 as the capacity provider. If using the default, specify this in your pool settings.
Ensure your pool configuration includes the ARN (Amazon Resource Name) for the ECS task.
3. Set Up Your ECS Cluster:
- Follow the AWS ECS Guide to create a cluster if you don't have one. You can refer to this link:
AWS ECS Cluster Setup Guide
4. Deploying a Simple Flow _(Example in Python)_:
python
from prefect import flow, task
@task(task_run_name="Adding {x} and {y}") # you can template arguments into the task name!
def add(x: int, y: int) -> int:
"""just a python function with a fancy hat on!"""
return x + y
@flow
def my_flow():
"""tasks must be called in the flow to be executed (at this time)"""
first_result = add(1, 2)
second_result = add(first_result, first_result)
return add(first_result, second_result)
if __name__ == "__main__":
# run the flow
my_flow()
Referenced Links:
- Prefect AWS ECS Integration Guide: https://docs.prefect.io/latest/integrations/prefect-aws/ecs_guide/
- Example Flow: https://raw.githubusercontent.com/zzstoatzz/prefect-code-examples/main/examples/tasks/basic.py
For detailed configuration on setting up ECS to work with EC2, it is recommended to read the AWS ECS documentation and the Prefect AWS ECS Integration Guide.Anton L.
08/23/2024, 9:04 PMMarvin
08/23/2024, 9:04 PMshell
prefect work-pool create --type ecs my-ecs-pool
4. Set Up Prefect Worker to Use ECS Task:
- Ensure that the worker within the ECS setup uses the correct task definition ARN when spinning up the ECS task.
Example Flow Code:
Here's an example of a basic Prefect flow that you can configure to run within your ECS task:
python
from prefect import flow, task
@task(task_run_name="Adding {x} and {y}") # You can template arguments into the task name!
def add(x: int, y: int) -> int:
"""Basic addition task"""
return x + y
@flow
def my_flow():
"""Placeholder for your tasks"""
first_result = add(1, 2)
second_result = add(first_result, first_result)
return add(first_result, second_result)
if __name__ == "__main__":
# Run the flow
my_flow()
Reference Links:
- Prefect AWS ECS Integration Guide: https://docs.prefect.io/latest/integrations/prefect-aws/ecs_guide/
- ECS Task Configuration Example Flow: https://raw.githubusercontent.com/zzstoatzz/prefect-code-examples/main/examples/tasks/basic.py
Further details can be sourced from the AWS ECS Documentation and the Prefect ECS Guide.