Hello, I have the setup env vars in flyte remote s...
# ask-the-community
f
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
FLYTE_INTERNAL_TASK_DOMAIN will not be used when using pyflyte run locally. did you see any error when running locally?
f
@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
the error should not happen. mind sharing you workflow code?
f
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
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
@Kevin Su, got it. Thanks!
160 Views