I have an AWS Lambda function (Python3.8) in which I am trying to connect to a RDS proxy using SQLAlchemy. I've confirmed that the function configuration will allow for this by also connecting to the proxy directly using PyMySQL. When I run the function, I get an error message of "(pymysql.err.InternalError) (3159, 'This RDS Proxy requires TLS connections')\n(Background on this error at: http://sqlalche.me/e/2j85)". The "background" for that error says nothing about TLS. I understand what I need to do (tell SQLAlchemy to connect using SSL/TLS), but I cannot figure out the syntax to do so. Below is my current code.
import pymysql
import sqlalchemy
from database_info import make_connection_str
print('connecting to database')
CONN_STR = make_connection_str()
ENGINE = sqlalchemy.create_engine(CONN_STR)
METADATA = sqlalchemy.MetaData(ENGINE)
TABLE = sqlalchemy.Table('active_prospect', METADATA, autoload=True) #error comes with this line
Things I've tried have been related to the following
- According to https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html
ssl-mode=REQUIREDis needed. pymysql.connect(... ssl={"true": True})works.
Based on those two things, I've tried every combination of (ssl-mode, ssl) = ('true', 'required') in two different ways.
CONN_STR += '?ssl-mode=REQUIRED'create_engine(CONN_STR, connect_args={'ssl': 'True'})
Results have varied. In some cases the error above has been replaced by AttributeError: 'str' object has no attribute 'get', still being raised from the same line.