Is there a way to specify my connection with SQLAlchemy to an AWS RDS Aurora Serverless MySQL database instance without a Secrets Manager ARN? I have the database username, password, endpoint, ARN, etc., and ideally I would initialize an engine, then use df.to_sql()
to load a DataFrame into a table on the Aurora instance.
...
else:
engine = create_engine([WHAT DO I SPECIFY HERE?])
with engine.connect() as conn:
df.to_sql([CODE TO APPEND TO EXISTING TABLE HERE])...
From Alchemy documentation - https://docs.sqlalchemy.org/en/13/dialects/mysql.html, this is what the connect string should look like - the parameter in create_engine - for MySQL
mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]
I don't know if you can connect to Aurora without a secrets ARN, but if you are willing to use one, you could install a driver like this: https://github.com/koxudaxi/py-data-api
Which would allow you to do something like the following:
def example_driver_for_sqlalchemy():
from sqlalchemy.engine import create_engine
engine = create_engine(
'mysql+pydataapi://',
connect_args={
'resource_arn': 'arn:aws:rds:us-east-1:123456789012:cluster:dummy',
'secret_arn': 'arn:aws:secretsmanager:us-east-1:123456789012:secret:dummy',
'database': 'test'
}
)
result: ResultProxy = engine.execute("select * from pets")
print(result.fetchall())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With