GitHub user 0ssigeno created a discussion: Connect to Aws RDS

Hi everyone, I have an RDS instance where I wanted to connect through my 
instance of superset, deployed inside an EC2 machine.

The easiest way that I found to carry out this task, is the following script 
inside a custom `config.py`
```python3
from sqlalchemy.engine.url import URL
import os

def db_connection_mutator(uri: URL, params, username, security_manager, source):
    import boto3

    client = boto3.client("rds", region_name=os.environ.get("AWS_REGION"))
    token = client.generate_db_auth_token(
        DBHostname=uri.host,
        Port=int(uri.port),
        DBUsername=uri.username,
    )
    return (
        URL(
            drivername=uri.drivername,
            username=uri.username,
            password=token,
            host=uri.host,
            port=uri.port,
            database=uri.database,
            query=uri.query,
        ),
        params,
    )


DB_CONNECTION_MUTATOR = db_connection_mutator
```
I had to recreate the URI object because, for whatever reason, it was not 
possible to change the password on the URI already formed.

Hope that this could help solve some headaches!

 

GitHub link: https://github.com/apache/superset/discussions/35827

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to