Hi folks, how would you configure PostgresFetch wh...
# prefect-community
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?
Hi @ale - to read in environment variables as secrets at runtime, you can use the
task. More info on that here: https://docs.prefect.io/core/concepts/secrets.html#environment-variables
Is there any example involving setting up a database connection by retrieving the connection info using EnvVarSecret?
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
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