Hi folks, how would you configure PostgresFetch wh...
# prefect-community
a
Hi folks, how would you configure PostgresFetch when the connection details are available into environment variables which exists only at runtime when the flow is executed on Fargate?
n
Hi @ale - to read in environment variables as secrets at runtime, you can use the
EnvVarSecret
task. More info on that here: https://docs.prefect.io/core/concepts/secrets.html#environment-variables
a
Is there any example involving setting up a database connection by retrieving the connection info using EnvVarSecret?
n
I don't have an example handy but you should be able to wrap the constructor in another task or subclass it and retrieve your runtime details in the subclassed run method:
Copy code
Class RuntimePostgresFetch(PostgresFetch):
  def run(self, user, db_name, password):
    # you can also call EnvVarSecret here
    # and set the connection details before calling
    # super.run
    self.user = user
    self.password = password
    self.db_name = db_name
    super(RuntimePostgresFetch, self).run()
^ class extension method OR
Copy code
@task
def postgres_fetch_wrapper(user, db_name, password, pg_query):
  return PostgresFetch(db_name=db_name, user=user, host='localhost').run(password=pg_pass, query=pg_query, fetch='all')
👍 1