https://prefect.io logo
Title
n

Noam Cohen

10/22/2022, 11:17 AM
Another one - my deployed flow cannot retrieve environmental variables from my local .env file. The file is in
.prefectignore
when I upload to my storage block and I am using a local agent. I am pretty sure that in the past this worked, but anyway - How can I set the environmental variables of my execution from an .
env
file?
1
The deployment
yaml
looks like
name: <FLOW-NAME>
description: null
version: c0a8d760333d670506d2fe9d4e56bfab
# The work queue that will handle this deployment's runs
work_queue_name: <SOME-LOCAL-AGENT-NAME>
tags: []
parameters: {}
schedule: null
infra_overrides: {}
infrastructure:
  type: process
  env: {}
  labels: {}
  name: null
  command: null
  stream_output: true
  block_type_slug: process
  _block_type_slug: process

###
### DO NOT EDIT BELOW THIS LINE
###
flow_name: blah
manifest_path: null
storage:
  bucket_path: <BUCKET-PATH>
  service_account_info: '*******'
  project: noamhome
  _block_document_id: 08c280eb-e0fa-4208-8bea-bbb25f3e9c2f
  _block_document_name: <BLOCK-NAME>
  _is_anonymous: false
  block_type_slug: gcs
  _block_type_slug: gcs
a

Anna Geller

10/22/2022, 12:43 PM
I have an example repo for you here that uses .env file to create blocks but generally, you should only use .env file for local development and once you need to create deployments, it's recommended to leverage blocks for storing credentials and configuration data needed for your business logic
check out this repo in more detail, e.g. this script shows how to locally load env vars from .env file and use it on blocks https://github.com/anna-geller/prefect-dataplatform/blob/main/utilities/create_blocks.py#L17
🙏 1
n

Noam Cohen

10/22/2022, 12:45 PM
thanks! You mean Secret block?
a

Anna Geller

10/22/2022, 2:28 PM
The secret block is just one example -- if you are currently setting credentials to AWS via
.env
file, you can instead leverage the
AwsCredentials
block available in the prefect-aws collection
there's block for almost anything 🙂 and if there isn't yet, there likely will be. If not, you can also create custom blocks to combine your secrets with your business logic - this repo has some examples for that as well