Robert Bastian
03/15/2021, 5:52 PM[2021-03-15 17:48:45,887] ERROR - rai-fargate | Error while deploying flow
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/prefect/agent/agent.py", line 414, in deploy_and_update_flow_run
deployment_info = self.deploy_flow(flow_run)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/prefect/agent/ecs/agent.py", line 322, in deploy_flow
resp = self.ecs_client.run_task(taskDefinition=taskdef_arn, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/client.py", line 676, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the RunTask operation: Task definition does not support launch_type FARGATE.
I checked the registered task definition and I can see:
"compatibilities": [
"EC2"
],
When I do the same with 0.14.6 I see:
"compatibilities": [
"EC2",
"FARGATE"
],
Thx!Zanie
Zanie
Robert Bastian
03/15/2021, 9:02 PMRUN_CONFIG = ECSRun(
labels=["s3-flow-storage", "rai-fargate-local"],
image="{redacted}.<http://dkr.ecr.us-east-1.amazonaws.com/prefect-aws:latest|dkr.ecr.us-east-1.amazonaws.com/prefect-aws:latest>",
memory="512",
cpu="256",
)
Storage:
STORAGE = S3(bucket="prefect-rai-dev")
Agent:
prefect agent ecs start --token {token} --cluster RAI --task-role-arn=arn:aws:iam::{redacted}:role/Prefect_Container_Role --execution-role-arn=arn:aws:iam::{redacted}:role/Prefect_Task_Execution_Role --log-level DEBUG --label rai-fargate-local --label s3-flow-storage --name rai-fargate
Robert Bastian
03/15/2021, 9:05 PMJim Crist-Harif
03/15/2021, 9:07 PMcompatibilities
in prefect itself, so it's not clear where this change is coming from.Jim Crist-Harif
03/15/2021, 9:09 PMRobert Bastian
03/15/2021, 9:19 PMRobert Bastian
03/15/2021, 9:19 PMJim Crist-Harif
03/15/2021, 9:24 PMJim Crist-Harif
03/15/2021, 9:25 PMJim Crist-Harif
03/15/2021, 9:25 PMRobert Bastian
03/15/2021, 9:27 PMRobert Bastian
03/15/2021, 9:28 PMFROM python:3.9-slim-buster
ENV PREFECT_VERSION=0.14.6
RUN apt-get update && apt-get install -y gcc
RUN pip install prefect[aws]==${PREFECT_VERSION}
COPY agent.py /agent.py
COPY --from=arpaulnet/s6-overlay-stage:2.0 / /
ENTRYPOINT ["/init"]
CMD ["python", "agent.py"]
I don’t explicitly install boto3. I’m relying on the Prefect “extras”Robert Bastian
03/15/2021, 9:31 PMJim Crist-Harif
03/15/2021, 9:35 PMJim Crist-Harif
03/15/2021, 9:36 PMZanie
Jim Crist-Harif
03/15/2021, 9:40 PMrequiresCompatibilities
on our task definitions. Still doesn't explain why the compatibilities changed for Robert when prefect was upgraded though (since we never set those and still don't).Robert Bastian
03/15/2021, 9:49 PMroot@f88173e2ea59:/# python
Python 3.9.2 (default, Mar 12 2021, 19:04:51)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> print(boto3.__version__)
1.17.27
>>> import botocore
>>> print(botocore.__version__)
1.20.27
>>> import prefect
>>> print(prefect.__version__)
0.14.12
Zanie
Robert Bastian
03/15/2021, 9:59 PMroot@9b11bf76222c:/# python
Python 3.9.2 (default, Mar 12 2021, 19:04:51)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import prefect
>>> print(prefect.__version__)
0.14.6
>>> import boto3
>>> print(boto3.__version__)
1.17.27
>>> import botocore
>>> print (botocore.__version__)
1.20.27
Robert Bastian
03/15/2021, 10:03 PMJim Crist-Harif
03/15/2021, 10:05 PMJim Crist-Harif
03/15/2021, 10:05 PMJim Crist-Harif
03/15/2021, 10:09 PMrequiresCompatibilities
on your task definition? Something like this should work:
import yaml
definition = yaml.safe_load(
"""
networkMode: awsvpc
cpu: 1024
memory: 2048
requiresCompatibilities:
- name: FARGATE
containerDefinitions:
- name: flow
"""
)
flow.run_config = ECSRun(task_definition=definition)
Robert Bastian
03/16/2021, 5:24 PMRobert Bastian
03/16/2021, 8:01 PMdefinition = yaml.safe_load(
"""
networkMode: awsvpc
cpu: 1024
memory: 2048
requiresCompatibilities:
- FARGATE
containerDefinitions:
- name: flow
executionRoleArn: aws:iam::{redacted}:role/Prefect_Task_Execution_Role
"""
)
RUN_CONFIG = ECSRun(
image= '{redacted}.<http://dkr.ecr.us-east-1.amazonaws.com/prefect-aws:latest|dkr.ecr.us-east-1.amazonaws.com/prefect-aws:latest>',
task_definition=definition,
labels=["s3-flow-storage"],
memory="512",
cpu="256",
)
It did take me 23 revisions to get the YAML just right (I hate YAML, btw).
I also don’t like that the name must equal “flow”. That doesn’t seem intuitive.Jim Crist-Harif
03/16/2021, 8:15 PMrequiresCompatibilities
ourselves (I think) and everything should still work. Should get a PR in for the next release.
I hate YAML, btwYaml isn't required here, it was just the quickest way I could copy over the existing def and add the bit you needed. A nested dict/list structure in python would have worked just as well. If you specify a custom definition via
task_definition_path
, then the file must contain yaml (or json, which is a subset of yaml).
I also don’t like that the name must equal “flow”. That doesn’t seem intuitive.Since task definitions may contain multiple containers, we need a way to know which container contains the flow for prefect to fill in the image/command/etc... To make it easier for users to define sidecar containers and leave the main container undefined we use the name
flow
as a designator, rather than assuming the first container definition. This is done for both ECS and k8s agents. Note that if you don't customize the containers at all you can leave the containerDefinitions
field out completely.Robert Bastian
03/16/2021, 11:31 PMJim Crist-Harif
03/17/2021, 12:28 AMBecause the role was set, EC2 validated that the flow was compatible with FARGATE. When the role is not there, FARGATE is not an option because you need (I assume) special permissions in the execution role.Ah, interesting. That doesn't happen in my test cluster (0.14.12 deploys fine on fargate in my test cluster), I wonder if there's some cluster-level settings that lead to this behavior? ECS has too many knobs. Since `task_role_arn`/`execution_role_arn` are top-level settings on both the agent and
ECSRun
objects, we moved setting these at runtime so user-provided templates wouldn't need them. It's annoying that execution_role_arn
seems to be required for at least your configuration.
Thanks for the info, this is all useful for figuring out how we should resolve this.Jim Crist-Harif
03/17/2021, 12:30 AMJim Crist-Harif
03/17/2021, 12:37 AMRobert Bastian
03/17/2021, 12:45 AM[rbastian@E007254-MAR18 ecs (master)]$ aws ecs describe-clusters --clusters RAI
{
"clusters": [
{
"clusterArn": "arn:aws:ecs:us-east-1:{redacted}:cluster/RAI",
"clusterName": "RAI",
"status": "ACTIVE",
"registeredContainerInstancesCount": 0,
"runningTasksCount": 0,
"pendingTasksCount": 0,
"activeServicesCount": 0,
"statistics": [],
"tags": [],
"settings": [
{
"name": "containerInsights",
"value": "enabled"
}
],
"capacityProviders": [],
"defaultCapacityProviderStrategy": []
}
],
"failures": []
}
Robert Bastian
03/17/2021, 1:02 AMJim Crist-Harif
03/17/2021, 1:17 AM"capacityProviders": ["FARGATE", "FARGATE_SPOT"]
, but other than that we're identical. How did you create a cluster without capacity providers? When creating a new cluster via the console with no other configuration this is what I get.Jim Crist-Harif
03/17/2021, 1:20 AMcapacityProviders
I can replicate your issue, I think I have enough to go on now. Thanks for your help in getting to the bottom of this issue!Robert Bastian
03/17/2021, 5:32 PMJim Crist-Harif
03/17/2021, 5:38 PMRobert Bastian
03/17/2021, 6:06 PMJim Crist-Harif
03/17/2021, 6:07 PMAn Amazon ECS task execution role is automatically created for you in the Amazon ECS console first-run experience
Jim Crist-Harif
03/17/2021, 6:07 PMRobert Bastian
03/17/2021, 6:07 PMJim Crist-Harif
03/17/2021, 6:08 PMJim Crist-Harif
03/17/2021, 6:08 PMRobert Bastian
03/17/2021, 6:14 PMJim Crist-Harif
03/17/2021, 6:15 PMRobert Bastian
03/17/2021, 6:16 PMJim Crist-Harif
03/17/2021, 6:17 PMRobert Bastian
03/17/2021, 6:17 PMRobert Bastian
03/17/2021, 7:30 PMRobert Bastian
03/17/2021, 7:42 PMJim Crist-Harif
03/17/2021, 7:50 PMJim Crist-Harif
03/17/2021, 7:51 PMRobert Bastian
03/17/2021, 8:00 PMJim Crist-Harif
03/17/2021, 8:05 PM{
"taskDefinition": {
"taskDefinitionArn": "...",
"containerDefinitions": [
{
"name": "flow",
"image": "prefecthq/prefect:0.14.12",
"cpu": 0,
"portMappings": [],
"essential": true,
"environment": [
{
"name": "PREFECT__CONTEXT__IMAGE",
"value": "prefecthq/prefect:0.14.12"
}
],
"mountPoints": [],
"volumesFrom": []
}
],
"family": "prefect-test-ecs",
"networkMode": "awsvpc",
"revision": 8,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE"
],
"cpu": "1024",
"memory": "2048"
}
}
Robert Bastian
03/17/2021, 8:28 PM"registeredBy": "arn:aws:iam::070551638384:user/prefect-service"
Jim Crist-Harif
03/17/2021, 8:32 PMRobert Bastian
03/30/2021, 9:48 PMTask definition does not support launch_type FARGATE.
You can see in the working task definition below that FARGATE is listed, but the only real difference I can see if that the image is now the default prefect image.
{
"taskDefinition": {
"taskDefinitionArn": "arn:aws:ecs:us-east-1:070551638384:task-definition/prefect-github-say-hello-flow:8",
"containerDefinitions": [
{
"name": "flow",
"image": "prefecthq/prefect:0.14.12",
"cpu": 0,
"portMappings": [],
"essential": true,
"environment": [
{
"name": "PREFECT__CONTEXT__IMAGE",
"value": "prefecthq/prefect:0.14.12"
}
],
"mountPoints": [],
"volumesFrom": []
}
],
"family": "prefect-github-say-hello-flow",
"networkMode": "awsvpc",
"revision": 8,
"volumes": [],
"status": "INACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE"
],
"cpu": "1024",
"memory": "2048",
"registeredAt": 1617140231.937,
"deregisteredAt": 1617140232.827,
"registeredBy": "arn:aws:iam::070551638384:user/prefect-service"
}
}
Just to clarify, my image on ECR is also 0.14.12.Jim Crist-Harif
03/31/2021, 8:09 PM