Hello, I have the setup env vars in flyte remote s...
# ask-the-community
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)?
FLYTE_INTERNAL_TASK_DOMAIN will not be used when using pyflyte run locally. did you see any error when running locally?
@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.
the error should not happen. mind sharing you workflow code?
Copy code
import os
from flytekit import task, workflow

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

def get_env_var() -> str:
    my_var = os.environ["ML_S3_BUCKET_PREFIX"]
    print(f'ML_S3_BUCKET_PREFIX: {my_var}')
    return my_var
def wf() -> None:
@Kevin Su, pyflyte run wf.py wf will fail.
pyflyte run --remote wf.py wf will work.
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]
@Kevin Su, got it. Thanks!