Tim Finkel
10/01/2021, 10:35 PMEssential container in task exited
. I’ve been trying to debug this for a bit and am not sure how to proceed. Any advice?Kevin Kho
Tim Finkel
10/01/2021, 10:38 PMexecution_role_arn
that I should make sure has the right permissions or something else?Kevin Kho
Kevin Kho
Tim Finkel
10/01/2021, 10:40 PMKevin Kho
Tim Finkel
10/02/2021, 1:41 AMTim Finkel
10/02/2021, 1:41 AMKevin Kho
Tim Finkel
10/02/2021, 2:19 PMEssential container in task exited
. Here’s the flow I’m trying to run:
import os
import time
import prefect
from prefect.storage import Docker
from prefect import task, Flow, Parameter
from prefect.run_configs import ECSRun
@task
def say_hello(name):
time.sleep(10)
greeting = os.environ.get('GREETING')
logger = prefect.context.get('logger')
<http://logger.info|logger.info>(f'{greeting}, {name}!')
with Flow('hello-flow-ecs') as flow:
people = Parameter('people', default=['Arthur', 'Ford', 'Marvin'])
say_hello.map(people)
flow.storage = Docker(
registry_url='<http://134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/|134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/>',
image_name='hello-flow-ecs',
image_tag='latest',
dockerfile='Dockerfile'
)
flow.run_config = ECSRun(
cpu='.25 vCPU',
memory='0.5 GB',
task_role_arn='arn:aws:iam::134777600073:role/prefectTaskRole',
execution_role_arn='arn:aws:iam::134777600073:role/ecsTaskExecutionRole',
run_task_kwargs=dict(cluster='prefectEcsCluster', launchType='FARGATE'),
env={'GREETING': 'Hello'},
image='prefect/hello-flow-ecs:latest'
)
flow.register(
project_name='Prefect Tutorial',
labels=['prod'],
add_default_labels=False
)
Let me know if you have any other ideas re: debugging or if anything looks obviously wrong!Kevin Kho
Kevin Kho
docker pull ecr_image_name
when you run this on local will be the same one you want to put in image='..'
. I think it might be image="<http://134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/hello-flow-ecs:latest|134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/hello-flow-ecs:latest>"
Tim Finkel
10/02/2021, 4:55 PMTim Finkel
10/02/2021, 4:55 PMimage='<http://134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/hello-flow-ecs:latest|134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/hello-flow-ecs:latest>'
Tim Finkel
10/02/2021, 4:57 PMtask_role_arn='arn:aws:iam::134777600073:role/ecsTaskExecutionRole'
might need to be task_role_arn='arn:aws:iam::134777600073:role/prefectECSAgentTaskExecutionRole'
Tim Finkel
10/02/2021, 4:58 PMTim Finkel
10/02/2021, 5:17 PMprefectECSAgentTaskExecutionRole
and prefectTaskRole
Kevin Kho
prefecthq/prefect
and then storing the flow in something easy to access like Github. Then you could test with this ECSRun and Github Storage that are definitely publicly pullable to verify it’s not something else?Kevin Kho
Tim Finkel
10/02/2021, 9:08 PMimport os
import time
import prefect
from prefect.storage import Docker
from prefect import task, Flow, Parameter
from prefect.run_configs import ECSRun
@task
def say_hello(name):
time.sleep(10)
greeting = os.environ.get('GREETING')
logger = prefect.context.get('logger')
<http://logger.info|logger.info>(f'{greeting}, {name}!')
with Flow('hello-flow-ecs') as flow:
people = Parameter('people', default=['Arthur', 'Ford', 'Marvin'])
say_hello.map(people)
flow.storage = Docker(
registry_url='<http://134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/|134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/>',
image_name='hello-flow-ecs',
image_tag='latest',
dockerfile='Dockerfile'
)
flow.run_config = ECSRun(
cpu='.25 vCPU',
memory='0.5 GB',
task_role_arn='arn:aws:iam::134777600073:role/prefectTaskRole',
execution_role_arn='arn:aws:iam::134777600073:role/prefectECSAgentTaskExecutionRole',
run_task_kwargs=dict(cluster='prefectEcsCluster', launchType='FARGATE'),
env={'GREETING': 'Hello'},
image='<http://134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/hello-flow-ecs:latest|134777600073.dkr.ecr.us-east-1.amazonaws.com/prefect/hello-flow-ecs:latest>'
)
flow.register(
project_name='Prefect Tutorial',
labels=['prod'],
add_default_labels=False
)
Kevin Kho
image="prefecthq/prefect:latest-python3.x"
where x is your major python versionTim Finkel
10/02/2021, 9:12 PMTim Finkel
10/02/2021, 9:12 PMKevin Kho
Kevin Kho
Kevin Kho
repo
and path
need to match the location in GithubKevin Kho
Tim Finkel
10/02/2021, 9:15 PMKevin Kho
pip install prefect[github]
Tim Finkel
10/02/2021, 9:21 PMKevin Kho
Kevin Kho
Tim Finkel
10/02/2021, 9:26 PMTim Finkel
10/02/2021, 9:26 PMTim Finkel
10/02/2021, 9:26 PMfrom prefect.agent.ecs.agent import ECSAgent
ecs_agent = ECSAgent(
cluster='arn:aws:ecs:us-east-1:134777600073:cluster/prefectEcsCluster',
labels=['prod']
)
ecs_agent.start()
Tim Finkel
10/02/2021, 9:27 PMTim Finkel
10/02/2021, 9:28 PMFailed to load and execute Flow's environment: UnknownObjectException(404, {'message': 'Not Found', 'documentation_url': '<https://docs.github.com/rest/reference/repos#get-a-repository>'}, {'server': '<http://GitHub.com|GitHub.com>', 'date': 'Sat, 02 Oct 2021 21:25:24 GMT', 'content-type': 'application/json; charset=utf-8', 'x-github-media-type': 'github.v3; format=json', 'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset', 'access-control-allow-origin': '*', 'strict-transport-security': 'max-age=31536000; includeSubdomains; preload', 'x-frame-options': 'deny', 'x-content-type-options': 'nosniff', 'x-xss-protection': '0', 'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'content-security-policy': "default-src 'none'", 'vary': 'Accept-Encoding, Accept, X-Requested-With', 'content-encoding': 'gzip', 'x-ratelimit-limit': '60', 'x-ratelimit-remaining': '59', 'x-ratelimit-reset': '1633213524', 'x-ratelimit-resource': 'core', 'x-ratelimit-used': '1', 'content-length': '112', 'x-github-request-id': '9E88:2E1B:2765784:4AB5E30:6158CE44'})
Tim Finkel
10/02/2021, 9:28 PMTim Finkel
10/02/2021, 9:28 PMKevin Kho
Tim Finkel
10/02/2021, 9:29 PMKevin Kho
Tim Finkel
10/02/2021, 9:33 PMTask 'say_hello': Exception encountered during task execution!
Tim Finkel
10/02/2021, 9:34 PMTim Finkel
10/02/2021, 9:34 PMKevin Kho
prefect agent ecs start --cluster arn:aws:ecs:us-east-2:12345678:cluster/test-cluster --label ecs_test_c --label ecs_test_d
But before you do that, try running this to authenticate:
aws ecr get-login-password | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$<http://AWS_REGION.amazonaws.com|AWS_REGION.amazonaws.com>
And then run the flow with the ecs agent running on your local machineTim Finkel
10/02/2021, 9:43 PMKevin Kho
Tim Finkel
10/02/2021, 9:44 PMKevin Kho
Tim Finkel
10/02/2021, 9:45 PMKevin Kho
get-login-password
. But let’s still test running the flow with an agent on your machine that we know how sure is authenticatedTim Finkel
10/02/2021, 9:48 PMTim Finkel
10/02/2021, 9:49 PMcluster/test-cluster
to something else?Tim Finkel
10/02/2021, 9:49 PMKevin Kho
Tim Finkel
10/02/2021, 9:50 PMKevin Kho
Tim Finkel
10/02/2021, 9:50 PMTim Finkel
10/02/2021, 9:51 PMprefect agent ecs start --cluster arn:aws:ecs:us-east-1:134777600073:prefectEcsCluster --label ecs_test_c --label ecs_test_d
should be good?Kevin Kho
Tim Finkel
10/02/2021, 9:51 PMTim Finkel
10/02/2021, 9:52 PMTim Finkel
10/02/2021, 9:52 PMKevin Kho
Tim Finkel
10/02/2021, 9:53 PMKevin Kho
Tim Finkel
10/02/2021, 9:54 PMTim Finkel
10/02/2021, 9:54 PMAnna Geller
Benjamin Bonhomme
10/15/2021, 2:15 PMEssential container in task exited
Any idea how to solve this?Anna Geller
Kevin Kho
task_definition = yaml.safe_load(
"""
cpu: 1024
memory: 2048
containerDefinitions:
- name: flow
logConfiguration:
logDriver: awslogs
options:
awslogs-group: /ecs/prefect-agent
awslogs-region: us-east-1
awslogs-stream-prefix: ecs
awslogs-create-group: 'true'
"""
)
ECSRun( ..., task_definition=task_definition)
we might be able to see if it’s low hanging fruit. Otherwise this might be networking/IAM related which will be a lot more involvedBenjamin Bonhomme
10/18/2021, 2:28 PMKevin Kho
Anna Geller
ECSRun(..., env="PREFECT__LOGGING__LEVEL":"DEBUG")
Benjamin Bonhomme
10/18/2021, 3:58 PM[2021-10-18 15:42:29,173] DEBUG - agent | Found 1 ready flow run(s): {'afb8c55f-c1fc-4cbc-926f-2d003bd538cc'}
[2021-10-18 15:42:29,174] DEBUG - agent | Retrieving metadata for 1 flow run(s)...
[2021-10-18 15:42:29,333] DEBUG - agent | Submitting flow run afb8c55f-c1fc-4cbc-926f-2d003bd538cc for deployment...
[2021-10-18 15:42:29,333] DEBUG - agent | Sleeping flow run poller for 0.25 seconds...
[2021-10-18 15:42:29,334] INFO - agent | Deploying flow run afb8c55f-c1fc-4cbc-926f-2d003bd538cc to execution environment...
[2021-10-18 15:42:29,335] DEBUG - agent | Updating flow run afb8c55f-c1fc-4cbc-926f-2d003bd538cc state from Scheduled -> Submitted...
[2021-10-18 15:42:29,540] DEBUG - agent | Registering new task definition for flow f35b13ff-12db-48d5-901d-fd9de5365e8e
[2021-10-18 15:42:29,585] DEBUG - agent | Querying for ready flow runs...
[2021-10-18 15:42:29,638] DEBUG - agent | Registered task definition arn:aws:ecs:eu-west-1:XXX:task-definition/prefect-ecs-slack-notify:23 for flow f35b13ff-12db-48d5-901d-fd9de5365e8e
[2021-10-18 15:42:29,998] DEBUG - agent | No ready flow runs found.
[2021-10-18 15:42:29,998] DEBUG - agent | Sleeping flow run poller for 0.5 seconds...
[2021-10-18 15:42:30,289] DEBUG - agent | Deregistering task definition arn:aws:ecs:eu-west-1:XXX:task-definition/prefect-ecs-slack-notify:23
[2021-10-18 15:42:30,344] DEBUG - agent | Started task 'arn:aws:ecs:eu-west-1:XXX:task/etl-jobs-ecs-cluster/YYY' for flow run 'afb8c55f-c1fc-4cbc-926f-2d003bd538cc'
[2021-10-18 15:42:30,345] INFO - agent | Completed deployment of flow run afb8c55f-c1fc-4cbc-926f-2d003bd538cc
[2021-10-18 15:42:30,498] DEBUG - agent | Querying for ready flow runs...
[2021-10-18 15:42:30,650] DEBUG - agent | No ready flow runs found.
[2021-10-18 15:42:30,650] DEBUG - agent | Sleeping flow run poller for 1.0 seconds...
Flow logs (log level on DEBUG too):
Application logs of my Java application (Slack Webhook saying Hi, I receive the message on the channel without problem)
I just replaced my AWS account_id with XXX and the container_id with YYY.
@Anna Geller, I can check the task on AWS with its ID logged by prefect, the container runs with the entrypoint I defined (the one from the PREFECT__CONTEXT__IMAGE defined in the task), does its job (in this case notifying me on slack), exits and then nothing happens as Prefect doesn't catch anything. Lazarus will try to run the task after a while.
Not sure it brings you a lot of light. If anything comes through your mind or you need some more information, I am here! 🙂Kevin Kho
Benjamin Bonhomme
10/19/2021, 9:43 AMBenjamin Bonhomme
10/19/2021, 1:09 PMAnna Geller
Benjamin Bonhomme
10/19/2021, 3:59 PMfrom prefect.run_configs import ECSRun
from prefect import Flow
import yaml
FLOW_NAME = "ecs_slack_notify"
IMAGE_NAME = "<http://XXX.dkr.ecr.eu-west-1.amazonaws.com/slack_notify_from_prefect:0.1|XXX.dkr.ecr.eu-west-1.amazonaws.com/slack_notify_from_prefect:0.1>"
EXECUTION_ROLE_ARN = "arn:aws:iam::XXX:role/PREFECT_ECS_AGENT_TASK_EXECUTION_ROLE"
TASK_ROLE_ARN = "arn:aws:iam::XXX:role/PREFECT_TASK_ROLE"
TASK_DEFINITION = yaml.safe_load(
"""
cpu: 256
memory: 512
containerDefinitions:
- name: flow
logConfiguration:
logDriver: awslogs
options:
awslogs-group: /ecs/prefect-agent
awslogs-region: eu-west-1
awslogs-stream-prefix: ecs
awslogs-create-group: 'true'
networkMode: awsvpc
"""
)
RUN_CONFIG = ECSRun(run_task_kwargs={'cluster': 'etl-jobs-ecs-cluster'},
labels=["prod"],
task_role_arn=TASK_ROLE_ARN,
execution_role_arn=EXECUTION_ROLE_ARN,
image=IMAGE_NAME,
memory=512,
cpu=256,
env={"PREFECT__LOGGING__LEVEL":"DEBUG"},
task_definition=TASK_DEFINITION)
flow = Flow(FLOW_NAME, run_config=RUN_CONFIG)
if __name__ == "__main__":
flow.register("etl-jobs")
Anna Geller
Benjamin Bonhomme
10/19/2021, 4:56 PMAnna Geller
Anna Geller
Benjamin Bonhomme
10/19/2021, 5:23 PMKevin Kho
RUN_CONFIG = ECSRun(run_task_kwargs={'cluster': 'etl-jobs-ecs-cluster'},
labels=["prod"],
task_role_arn=TASK_ROLE_ARN,
execution_role_arn=EXECUTION_ROLE_ARN,
image=IMAGE_NAME,
memory=512,
cpu=256,
env={"PREFECT__LOGGING__LEVEL":"DEBUG"},
task_definition=TASK_DEFINITION)
with Flow(FLOW_NAME, run_config=RUN_CONFIG) as flow:
task(lambda x: True)(0)
just to put a task there because the issue is that there is no task right now inside the Flow. I think the Docker entrypoint will still run here so you will achieve running it, but if you rely on the ENTRYPOINT to execute it, it’s not a Prefect task and you won’t get errors or logging around the Java program execution.Kevin Kho
shell_task = ShellTask(...)
with Flow(FLOW_NAME, run_config=RUN_CONFIG) as flow:
shell_task(cmd=entrypoint_cmd_here)
and this will give you the observability and logging around the running of that task.Kevin Kho
boto3 run_task
as a Prefect task to invoke it.Kevin Kho
ShellTask
will be executed on the container defined in the ECS task definition. The ShellTask will run on that ECS taskBenjamin Bonhomme
10/20/2021, 9:16 AMAnna Geller
Benjamin Bonhomme
10/20/2021, 4:49 PMKevin Kho
ShellTask
to work, you would need to build your own container that has Java I think. Could you elaborate a bit how you went about it? Did you create a container, remove the entrypoint, supply that to ECSRun, and then call the shell task in the Flow? Could you show me the updated codeAnna Geller
ShellTask
and get stdout and stderr from the Java app into Prefect. Here is an example https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-buildsBenjamin Bonhomme
10/21/2021, 7:56 AMFROM prefecthq/prefect:latest-python3.8
)
Afterward, I install the Java runtime necessary to run the Java Jobs (openjdk-11-jre-headless
)
As for the Java part of it I just COPY the .zip file and unzip it in the working directory, containing the shell script and the Jar files necessary for the run.
So both Prefect & a Java runtime are embedded in the container. The images have no Entrypoint
note: the .sh file is copied at /
Here is the code:
from prefect.run_configs import ECSRun
from prefect import Flow
from prefect.storage import Docker
from prefect.tasks.shell import ShellTask
import yaml
FLOW_NAME = "ecs_slack_notify"
IMAGE_NAME = "<http://XXX.dkr.ecr.eu-west-1.amazonaws.com/slack_notify_from_prefect:0.1|XXX.dkr.ecr.eu-west-1.amazonaws.com/slack_notify_from_prefect:0.1>"
EXECUTION_ROLE_ARN = "arn:aws:iam::XXX:role/PREFECT_ECS_AGENT_TASK_EXECUTION_ROLE"
TASK_ROLE_ARN = "arn:aws:iam::XXX:role/PREFECT_TASK_ROLE"
TASK_DEFINITION = yaml.safe_load(
"""
cpu: 256
memory: 512
containerDefinitions:
- name: flow
logConfiguration:
logDriver: awslogs
options:
awslogs-group: /ecs/prefect-agent
awslogs-region: eu-west-1
awslogs-stream-prefix: ecs
awslogs-create-group: 'true'
networkMode: awsvpc
"""
)
RUN_CONFIG = ECSRun(run_task_kwargs={'cluster': 'etl-jobs-ecs-cluster'},
labels=["prod"],
task_role_arn=TASK_ROLE_ARN,
execution_role_arn=EXECUTION_ROLE_ARN,
image=IMAGE_NAME,
memory=512,
cpu=256,
env={"PREFECT__LOGGING__LEVEL":"DEBUG"},
task_definition=TASK_DEFINITION)
task = ShellTask()
with Flow(FLOW_NAME, run_config=RUN_CONFIG) as flow:
print("Flow starts")
run_container = task(command="/bin/sh -c slack_notify_from_prefect_run.sh")
flow.storage = Docker(
registry_url="<http://XXX.dkr.ecr.eu-west-1.amazonaws.com|XXX.dkr.ecr.eu-west-1.amazonaws.com>",
image_name="flows_storage",
image_tag="latest",
dockerfile="Dockerfile-flow-storage"
)
flow.storage.build()
if __name__ == "__main__":
flow.register("talend-jobs")
Anna Geller
Benjamin Bonhomme
10/21/2021, 11:44 AMAnna Geller
WORKDIR /your/path
by default, the Docker storage uses /opt/prefect/flows to store flows.
Overall, what may make it all a bit more difficult is that you use Docker storage. Perhaps if you would use S3 Storage as a flow storage instead, this would be easier? because you have no dependencies in your flow at all, and your custom image that you supply to ECSRun covers all dependencies. So I think changing the storage to S3 could make things easier. This is how you could use it:
from prefect.storage import S3
FLOW_NAME = "s3_storage_demo"
STORAGE = S3(
bucket="prefect-datasets",
key=f"flows/{FLOW_NAME}.py",
stored_as_script=True,
# if you add local_script_path, Prefect will upload the local Flow script to S3 during registration
local_script_path=f"{FLOW_NAME}.py",
)
Benjamin Bonhomme
10/21/2021, 5:12 PMBring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by