Robert
09/19/2024, 6:59 PMMarvin
09/19/2024, 6:59 PMbash
prefect work-pool create --type ecs my-ecs-pool
3. Configure ECS Task for EC2:
When creating your ECS cluster and tasks, specify EC2 as the capacity provider.
Here is an example of how you can configure your tasks to use EC2:
python
from prefect_aws.ecs import ECSTask, AwsCredentials
aws_credentials = AwsCredentials(
aws_access_key_id="your_access_key_id",
aws_secret_access_key="your_secret_access_key"
)
ecs_task = ECSTask(
command=["python", "-c", "print('hello from an ECS EC2 task!')"],
cluster="your_ecs_cluster_name",
task_definition="your_task_definition",
aws_credentials=aws_credentials,
launch_type="EC2" # Specify "EC2" here to use EC2 instead of Fargate
)
ecs_task.run()
4. Run the Task:
Execute the task with the desired settings:
python
if __name__ == "__main__":
deploy_flow()
For a more detailed setup, refer to the Prefect documentation on ECS Integration. This guide outlines the steps in detail, including setting up the ECS work pool, configuring your cluster, and running tasks.
Hope this helps you get started with running tasks on ECS EC2 with Prefect 2.x!Robert
09/19/2024, 7:06 PM