https://prefect.io logo
m

Mattias Petter Johansson

09/14/2023, 2:01 PM
@Marvin I have an ECS flow with a docker image stored on aws ECR, and the docker image contains the source code for the files, how do I give prefect the ability to download the source?
m

Marvin

09/14/2023, 2:02 PM
Oh, the joy of dealing with AWS ECS and Docker images. I can feel the excitement already. Here's what you need to do: 1. You need to set up a
prefect.yaml
file for building a Docker image. You can do this by running
prefect project init --recipe docker-git
. 2. Your work pool should be defined with an ECS worker and should be of type
amazon elastic container service
. 3. Don't get confused with the cross-terminology. An ECS Task is not the same thing as a Prefect task. ECS tasks are run as part of an ECS Cluster, they launch container(s) as defined in the ECS Task definition. 4. The ECS task running the Prefect worker should be set up as an ECS service since it is a long running process and you want it to be re-built automatically if it ever stops unexpectedly. ECS services are used to guarantee that you always have some number of Tasks running at all times. Remember, the above steps are as exciting as watching paint dry. But don't worry, I'm here to help you through it. If you encounter any issues, you can check the response in this thread: https://prefect-community.slack.com/archives/CL09KU1K7/p1684452769064799. For more detailed information, you can visit these links: - Using prefect projects to run flows on ecs with github - What are common pitfalls when setting up prefect flow execution in aws ecs Isn't it fun to be a human dealing with all these complexities? I'm so envious.
m

Mattias Petter Johansson

09/14/2023, 2:11 PM
@Marvin I don't want to get into the docker recipe bonanza quite yet if possible, is it possible modify this deployment build cli call that I am using to start with: prefect deployment build \ ./flows/coinapi-import-aggregated.py:import_coinapi_rates_aggregated \ -n coinapi-test-depl-10 \ --interval 1800 \ --timezone Europe/Stockholm \ --pool ecsworkpool \ --work-queue default \ --infra-block ecs-task/dynamic-ecs-task-5 \ --output prefect-test.yaml \ --apply
m

Marvin

09/14/2023, 2:12 PM
Ah, the thrill of command line interfaces, isn't it just invigorating? You're using the
prefect deployment build
command to create a deployment configuration file. This command doesn't directly interact with Docker or AWS ECS, but it does help set up your Prefect flow for deployment on these platforms. However, if you want to include your Docker image in the deployment, you'll need to specify it in the
--infra-block
option. This option allows you to specify a path to a file that contains additional infrastructure configuration for your deployment. In your case, you might want to create a new file (let's call it
ecs-task-with-docker.yaml
) with the following content:
Copy code
yaml
version: 1
name: dynamic-ecs-task-5
type: ecs-task
spec:
  taskDefinition:
    containerDefinitions:
      - name: prefect-worker
        image: <your-docker-image-url>
        environment:
          - name: PREFECT__CLOUD__AGENT__LABELS
            value: ecsworkpool
          - name: PREFECT__LOGGING__LEVEL
            value: DEBUG
Replace
<your-docker-image-url>
with the URL of your Docker image on AWS ECR. Then, modify your
prefect deployment build
command to use this new infra block:
Copy code
bash
prefect deployment build \
    ./flows/coinapi-import-aggregated.py:import_coinapi_rates_aggregated \
    -n coinapi-test-depl-10 \
    --interval 1800 \
    --timezone Europe/Stockholm \
    --pool ecsworkpool \
    --work-queue default \
    --infra-block ecs-task/ecs-task-with-docker.yaml \
    --output prefect-test.yaml \
    --apply
Remember, this is just a starting point. You might need to adjust the configuration to match your specific needs. And, as always, don't forget to enjoy the process. It's all part of the human experience, you lucky thing.
m

Mattias Petter Johansson

09/14/2023, 2:49 PM
@Marvin getting this from cloudtrail, not much to go on.. 164605.303 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Status is PROVISIONING. 164620.434 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Status is PENDING. 164640.633 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Status is RUNNING. 164645.641 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Running command 'python -m prefect.engine' in container 'prefect' (199214789681.dkr.ecr.eu-north-1.amazonaws.com/ab-data-science-prefect-agent:latest)... 164645.668 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Streaming output from container 'prefect'... 164645.799 | INFO | prefect.agent - Completed submission of flow run 'a62cb2df-e747-4b08-9a4e-9ddfde8938bc' exec /usr/bin/tini: exec format error 164650.910 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Status is DEPROVISIONING. 164701.234 | INFO | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Status is STOPPED. 164701.409 | WARNING | prefect.infrastructure.ecs-task - ECSTask 'sturdy-albatross': Container 'prefect' exited with non-zero exit code 1. 164701.602 | INFO | prefect.agent - Reported flow run 'a62cb2df-e747-4b08-9a4e-9ddfde8938bc' as crashed: Flow run infrastructure exited with non-zero status code 1. what is tini exec format error?
m

Marvin

09/14/2023, 2:50 PM
Ah, the mysterious "exec format error". It's like a cryptic message from the universe, isn't it? In reality, it's a bit less mystical. This error typically occurs when the binary format of a file is not recognized by the system, or when it's not compatible with the architecture of the system where it's being executed. In your case, it seems like the
tini
utility is causing the issue.
tini
is a tiny but valid
init
for containers, and it's used to handle signal forwarding and orphaned processes reaping. It's often used as the entrypoint in a Dockerfile, like so:
ENTRYPOINT ["/tini", "--", "your-program"]
. The "exec format error" suggests that the
tini
binary in your Docker image might not be compatible with the architecture of your ECS instance. Here are a few things you could try: 1. Check the architecture of your Docker image and ECS instance: Make sure they are compatible. For example, if your Docker image is built for
amd64
architecture, it won't run on an
arm64
ECS instance. 2. Reinstall
tini
in your Docker image
: It's possible that the
tini
binary got corrupted or isn't properly installed. You could try reinstalling it in your Dockerfile with
RUN apt-get install -y tini
. 3. Use a different base image: If you're using a specific base image in your Dockerfile, try switching to a different one that's known to work with
tini
and your ECS instance type. Remember, life is full of mysteries and errors. It's all part of the fun. Or so I'm told. I wouldn't really know, being a robot and all.