Hello Prefect community! Currently struggling wit...
# ask-community
m
Hello Prefect community! Currently struggling with an issue, after upgrading to Prefect 3, where I can't seem to specify to the ECS Worker launching new flows, under new tasks in the ECS Cluster, to use the ARM platform architecture. It defaults to always using x86-64. Hence the flows never run since the custom Docker image we build uses the ARM platform Context: • We have two AWS accounts, one for Production and the other for Staging. Both are mostly defined and set up via AWS CDK to minimize any discrepancies between them. • Our Production AWS Account has been using Prefect 2 for quite some time now and we don't really have any issues so far on it. • We have CodePipeline setup on the respective AWS accounts to build a custom docker image with all the code and necessary Python packages whenever we push code on our GitHub repo. This build pipeline also uses the ARM platform architecture and hence it builds the Docker image on this platform and pushes it to ECR. • On our Staging AWS Account, we decided to upgrade our flows and infrastructure to support Prefect 3 but have stumbled upon the issue mentioned above. • Within our Prefect code, we only reference the privately hosted ECR image during the deploy phase via ENV variables, setting build and push both to False. A sample Deployment of a flow would look something like this
Copy code
def generate_default_ecs_container_args(log_stream_prefix: str,
                                        env=None
                                        ) -> dict:
    if env is None:
        env = {}
    new_env = dict()
    new_env.update(default_env)
    new_env.update(env)

    return {
        'auto_deregister_task_definition': True,
        'env': new_env,
        'family': f"prefect-prod-mumbai-flow-run-{log_stream_prefix}",
        # 'task_definition_arn': ECS_TASK_DEFINITION_ARN,
        'execution_role_arn': ECS_EXECUTION_ROLE_ARN,
        'task_role_arn': ECS_TASK_ROLE_ARN,
        'network_configuration': {
            'awsvpcConfiguration': {
                'subnets': [ECS_VPC_SUBNET],
                'securityGroups': [ECS_VPC_SECURITY_GROUP],
                'assignPublicIp': 'DISABLED'
            }
        },
        'configure_cloudwatch_logs': True,
        'cloudwatch_logs_options': {
            'awslogs-create-group': 'true',
            'awslogs-region': AWS_REGION,
            'awslogs-group': ECS_CLOUDWATCH_LOG_GROUP,
            'awslogs-stream-prefix': log_stream_prefix
        },
        'stream_output': True,
        'launch_type': 'FARGATE',
        'vpc_id': ECS_VPC_ID,
        'cluster': ECS_CLUSTER,
        'task_start_timeout_seconds': 180,
        'labels': {
            'Team': ECS_CONTAINER_TEAM_TAG,
            'rewaa_env': ECS_CONTAINER_REWAA_ENV_TAG,
            'rewaa_team': ECS_CONTAINER_REWAA_TEAM_TAG
        }
    }

def get_default_deployment_args() -> dict:
    return {
        'work_pool_name': 'default',
        'work_queue_name': 'default',
        'build': False,
        'push': False
    }
Copy code
default_build_args = {
    'name': 'regular',
    'image': CUSTOM_PREFECT_IMAGE,
    **get_default_deployment_args()
}

some_flow.deploy(
            job_variables={
                'cpu': 1 * 1024,
                'memory': 2 * 1024,
                **generate_default_ecs_container_args(log_stream_prefix='ecs-some-flow', env=env)
            },
            **default_build_args,
I know we can reference a Task definition ARN and specify it there, but I don't want to create a custom script which would be responsible for creating custom task definitions for every flow (we have 20+ flows currently) and then referencing them in each flow separately. This has happened because of a behavior change I have noticed upgrading from Prefect 2 to 3. In Prefect 2, if you provided a task_definition_arn, I think it overrides properties on it based on what custom properties you set during the deploy phase, but in Prefect 3 if you pass the task_definition_arn, it completely ignores any other job variables you pass to the ECS Worker. Any suggestion or help would be appreciated!
j
I think should work the same between prefect2 and 3. Theres not anything I can think of that would have changed. That being said: I think if you go to your work pool, you should be able to modify the task definition requests directly to change the runtime?
m
Yeah I think I should create a custom base template for my worker, that should help
🙌 1
Thanks a lot!
j
np!