https://flyte.org logo
#ask-the-community
Title
# ask-the-community
f

Frank Shen

02/10/2023, 5:12 PM
Hello, I have the setup env vars in flyte remote server and can retrieve them via os.environ.get(“env-var”) and also can get the domain value via os.environ.get(“FLYTE_INTERNAL_TASK_DOMAIN”) in task running on the flyte remote. However, this will not work if I run the task locally, because the keys are not set locally. How do I configure my local machine if I want to run the tasks locally to retrieve the same env-vars and FLYTE_INTERNAL_TASK_DOMAIN (pyflyte run locally)?
k

Kevin Su

02/10/2023, 8:40 PM
FLYTE_INTERNAL_TASK_DOMAIN will not be used when using pyflyte run locally. did you see any error when running locally?
f

Frank Shen

02/10/2023, 9:25 PM
@Kevin Su, KeyError: ‘FLYTE_INTERNAL_TASK_DOMAIN’ KeyError: ‘env-var’
@Kevin Su, it’s awkward that users have to alter code to run the tasks locally verses remotely to avoid this runtime keyError.
k

Kevin Su

02/10/2023, 10:52 PM
the error should not happen. mind sharing you workflow code?
f

Frank Shen

02/11/2023, 12:17 AM
Copy code
import os
from flytekit import task, workflow

@task
def get_domain() -> str:
    domain = os.environ["FLYTE_INTERNAL_TASK_DOMAIN"]
    print(f'FLYTE_INTERNAL_TASK_DOMAIN: {domain}')
    return domain

@task
def get_env_var() -> str:
    my_var = os.environ["ML_S3_BUCKET_PREFIX"]
    print(f'ML_S3_BUCKET_PREFIX: {my_var}')
    return my_var
@workflow
def wf() -> None:
    get_env_var()
    get_domain()
@Kevin Su, pyflyte run wf.py wf will fail.
pyflyte run --remote wf.py wf will work.
k

Kevin Su

02/11/2023, 12:39 AM
ohh, FLYTE_INTERNAL_TASK_DOMAIN is only used when running remotely. you can set a default value for it.
Copy code
domain = os.getenv("FLYTE_INTERNAL_TASK_DOMAIN", "default_value")
or return optional type
Copy code
def get_domain() -> Optional[str]
f

Frank Shen

02/11/2023, 12:59 AM
@Kevin Su, got it. Thanks!
3 Views