title: Pony ORM and IAM based connection to AWS PostgreSQL RDS
body: <p>I am building a service using Python, Pony ORM and PostgreSQL. I plan hosting it in AWS. I will use AWS RDS PostgreSQL.</p>
  <p>AWS supports passwordless connection to RDS (<a href="https://aws.amazon.com/premiumsupport/knowledge-center/rds-postgresql-connect-using-iam/" rel="nofollow noreferrer">https://aws.amazon.com/premiumsupport/knowledge-center/rds-postgresql-connect-using-iam/</a>, <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Python.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Python.html</a>).</p>
  <p>Essentially, I have to generate a short-living password before connecting to my database:</p>
  <pre><code>session = boto3.Session(profile_name='RDSCreds')
  client = session.client('rds')
  token = client.generate_db_auth_token(DBHostname=ENDPOINT, Port=PORT, DBUsername=USER, Region=REGION)
  conn = psycopg2.connect(host=ENDPOINT, port=PORT, database=DBNAME, user=USER, password=token, sslrootcert=&quot;SSLCERTIFICATE&quot;)
  </code></pre>
  <p>Is there a way to integrate this approach with Pony ORM? Under the hood Pony just delegates connection to <code>psycopg2</code>. <code>psycopg2</code> accepts username and password. But how can I make sure that when Pony reconnects to the database, there's a token that it can use?</p>