You can modify how the engine makes connections using the do_connect event hook:
https://docs.sqlalchemy.org/en/13/core/events.html?highlight=do_connect#sqlalchemy.events.DialectEvents.do_connect each time the engine/ pool go to make a new connection, you can affect all the arguments here, or return an actual DBAPI connection. On Fri, May 22, 2020, at 1:39 PM, Ryan Kelly wrote: > Hi, > > I am looking to use credentials provided by the above functionality from AWS. > Basically, using either of these methods, you can obtain temporary > credentials (for RDS, just password, and Redshift both username and password) > that can be used to access the database. However, for long running processes, > connection failures and subsequent reconnections as well as new connections > initiated by the connection pool (or even just waiting a long time between > generating the credentials and making your first connection) the credentials > configured on a URL as passed to create_engine will eventually begin to fail. > > At first I thought I'd simply subclass URL and make username/password > properties that could be refreshed as needed, but digging into > create_connection it seems like those properties are read out of the URL > object and into cargs/cwargs and provided to pool as such. > > I took then a roundabout approach or creating a proxy object that is capable > of refreshing the value and using this object as the username/password, which > only works because psycogp2 is helpfully calling str() on them as it > constructs the connstring/dsn. Which... I mean, is an interesting, but also > unsustainable, solution. > > What I am asking, I suppose, is 1) am I missing something obvious that would > make this achievable? and 2) if not, what kind of best-approach pull request > could I produce that could make this happen? > > Thanks, > -Ryan > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/CAHUie25g0G5OPuyDHaNn8oWkTzizwQxGY0tnkaJvOewLMQR4DQ%40mail.gmail.com > > <https://groups.google.com/d/msgid/sqlalchemy/CAHUie25g0G5OPuyDHaNn8oWkTzizwQxGY0tnkaJvOewLMQR4DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/d1bed41d-9fa2-4761-a963-c87720cf25b2%40www.fastmail.com.