Search code examples
pythonsqlalchemyaws-secrets-managerpandas-to-sqlaws-aurora-serverless

Python Connect to AWS Aurora Serverless MySQL Using SQLAlchemy


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])...

Solution

  • 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>]