This message was deleted.
# prefect-community
s
This message was deleted.
n
@Sebastián Montoya Tapia hey! happy to take a look at this can you move your code block into this thread?
s
Copy code
from datetime import datetime
from prefect import Flow
from prefect.tasks.secrets import PrefectSecret
from tasks.extract import function_1, function_2
from tasks.load import function_1, function_2
from prefect.storage import S3
from prefect.run_configs import ECSRun
import os

ENV_1 = os.environ.get('ENV_1')
ENV_2 = os.environ.get('ENV_2')
AWS_IAM_ID = os.environ.get('AWS_IAM_ID')
FLOW_NAME = "flow-name"
IMAGE_NAME= "flow-name-image"
STORAGE = S3(
    bucket="fantasy-bucket",
    key=f"{IMAGE_NAME}/flow.py",
    stored_as_script=True,
    # this will ensure to upload the Flow script to S3 during registration
    local_script_path=f"flow/src/flow.py",
)
RUN_CONFIG = ECSRun(
    labels=["super-label"],
    task_role_arn=f"arn:aws:iam::{AWS_IAM_ID}:role/fantasyTaskRole",
    execution_role_arn=f"arn:aws:iam::{AWS_IAM_ID}:role/fantasyExecutionRole",
    run_task_kwargs=dict(cluster="superCluster", launchType="FARGATE",),
    env={
        "PREFECT__CONTEXT__SECRETS__ENV_1": ENV_1,
        "PREFECT__CONTEXT__SECRETS__ENV_2": ENV_2
    },
    image=f"{AWS_IAM_ID}.<http://dkr.ecr.any-az.amazonaws.com/{IMAGE_NAME}:latest|dkr.ecr.any-az.amazonaws.com/{IMAGE_NAME}:latest>"
)

with Flow(FLOW_NAME, storage=STORAGE, run_config=RUN_CONFIG) as flow:
    # Lots of tasks in here
    super_taks = super_task_function()

# Register the flow
flow.register("ProjectName")
@Nate is it necessary to move the other code block with the project structure into the thread ?
n
@Sebastián Montoya Tapia no that's fine - thank you! do you mind sharing the contents of your dockerfile?
s
Sure!
Copy code
FROM prefecthq/prefect:1.2.4-python3.8
RUN apt-get update && apt-get upgrade -y
# package for psycopg2 
RUN apt-get install libpq-dev -y 
RUN /usr/local/bin/python -m pip install --upgrade pip
WORKDIR /opt/prefect
COPY src/ /opt/prefect/flow/src/
COPY requirements.txt .
COPY setup.py .
RUN pip install .
n
@Sebastián Montoya Tapia I recreated your file structure, built the image the same way, and was able to run my flow as expected
I'm wondering if you've seen this documentation on running ECS in production also, I recommend a project file structure more like this (if possible)
s
Finally I was able to run it succesfully using this repository https://github.com/eidos-ai/prefect-aws-boilerplate
🙌 1
👍 2
The only difference was the storage