https://prefect.io logo
a

ale

10/09/2020, 2:05 PM
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

nicholas

10/09/2020, 2:07 PM
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

ale

10/09/2020, 2:36 PM
Is there any example involving setting up a database connection by retrieving the connection info using EnvVarSecret?
n

nicholas

10/09/2020, 2:55 PM
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