Sean Malone
06/21/2024, 11:40 PMMarvin
06/21/2024, 11:41 PMprefect.yaml
configuration:
1. ECR Repository Setup:
- Create your ECR repository using AWS CLI:
sh
aws ecr create-repository --repository-name <my-ecr-repo> --region <region>
2. Creating prefect.yaml
:
- Define your ECR image and ECS worker in the prefect.yaml
file. Below is a template:
yaml
name: ecs-worker-guide
prefect-version: 2.14.20
build:
- prefect_docker.deployments.steps.build_docker_image:
id: build_image
requires: prefect-docker>=0.3.1
image_name: <my-ecr-repo>
tag: latest
dockerfile: auto
push:
- prefect_docker.deployments.steps.push_docker_image:
requires: prefect-docker>=0.3.1
image_name: '{{ build_image.image_name }}'
tag: '{{ build_image.tag }}'
deployments:
- name: my_ecs_deployment
entrypoint: flow.py:my_flow
work_pool:
name: ecs-dev-pool
job_variables:
image: '{{ build_image.image }}'
pull:
- prefect.deployments.steps.set_working_directory:
directory: /opt/prefect/
3. Execution:
- Use Prefect to build and push your defined Docker image:
sh
prefect deployment build -n my_ecs_deployment
- Deploy your flow to the ECS cluster:
sh
prefect deployment apply
These steps ensure that your ECS worker uses the specified ECR image for flow execution, allowing for scalable and reproducible deployments.
For more details, refer to Prefect ECS Guide.Nate
06/21/2024, 11:42 PMprefect deploy
nowSean Malone
06/22/2024, 12:01 AMprefect worker start
) and the actual execution of my flow ( which ideally is running my_flow.py
via a different Docker container).Nate
06/22/2024, 12:03 AMSean Malone
06/22/2024, 12:06 AMprefecthq/prefect:2-python3.10
). But for the flow run, I have a custom image on ECR that contains the flow code I want to run.Nate
06/22/2024, 12:08 AMimage
variable of your ECS work pool)
if you dont want to have building/pushing the image as a part of the prefect deploy
, you can remove those build
and push
steps and hardcode a reference to your ECR image in the override or make a Variable that you reference there so you can change it out later without changing your prefect.yaml
Sean Malone
06/22/2024, 12:18 AMFile "/usr/local/lib/python3.10/site-packages/prefect_aws/workers/ecs_worker.py", line 981, in _register_task_definition
response = ecs_client.register_task_definition(**task_definition)
File "/usr/local/lib/python3.10/site-packages/botocore/client.py", line 565, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.10/site-packages/botocore/client.py", line 1021, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ClientException: An error occurred (ClientException) when calling the RegisterTaskDefinition operation: Fargate requires task definition to have execution role ARN to support ECR images.
Which seems strange because 1. I’ve defined the task definition/execution role for the ecs service 2. Checked the permission policies on the execution role. I tried following the Prefect ECS Guide as close as i could. Any thoughts on where to look?Nate
06/22/2024, 12:23 AMSean Malone
06/22/2024, 12:29 AM{
"family": "prefect-worker-task",
"networkMode": "awsvpc",
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "512",
"memory": "1024",
"executionRoleArn": "<ecs-task-role-arn>", <--- HERE
"taskRoleArn": "<ecs-task-role-arn>", <--- HERE
"containerDefinitions": [
If so yes, if not, not sure I know where else I set the executeion role ARN. (also i’m using the same ARN for both execution + task for this scenario)Nate
06/22/2024, 12:32 AMSean Malone
06/22/2024, 12:40 AMNate
06/22/2024, 12:42 AMNate
06/22/2024, 12:43 AMvariables
Nate
06/22/2024, 12:43 AMjob_variables
section of your deployment in the prefect.yaml
just like other things like image
Nate
06/22/2024, 12:44 AMSean Malone
06/22/2024, 12:45 AMNate
06/22/2024, 12:46 AM