To pass environment variables to a Flyte launch plan that is a cron job, you can use the
pyflyte run --env
command. This allows you to set environment variables when executing the launch plan.
1.
Define the Launch Plan: Create a launch plan with a cron schedule.
2.
Set Environment Variables: Use
pyflyte run --env
to pass the environment variables during execution.
Example:
from flytekit import LaunchPlan, CronSchedule, task, workflow
@task
def my_task() -> str:
import os
return os.getenv("MY_ENV_VAR", "default_value")
@workflow
def my_workflow() -> str:
return my_task()
cron_lp = LaunchPlan.get_or_create(
name="my_cron_lp",
workflow=my_workflow,
schedule=CronSchedule(schedule="0 */6 * * *"), # Every 6 hours
)
# Run the launch plan with environment variables
# pyflyte run --env MY_ENV_VAR=my_value my_module.py my_workflow
For more details, refer to
Flyte discussion on setting environment variables.
Would you like more detail?
Sources:
-
Flyte discussion on setting environment variables
-
Flyte discussion on passing custom environment variables 👍 0 button 👎 0 button 💡
Hint: Mention @runllm in the thread for followups.