I'm trying to send data to a MySQL database hosted on AWS' RDS using a Lambda function. However, when I try to import the mysql module with import mysql.connector I get a "Runtime.ImportModuleError" error.
I've tried finding a python file for the mysql.connector online to upload to the function with no luck.
import mysql.connector
def lambda_handler(event, context):
mydb = mysql.connector.connect(
host="test.url.us-west-2.rds.amazonaws.com",
user="root",
passwd="password",
database="test")
mycursor = mydb.cursor()
sql = "INSERT INTO table VALUES ('test')"
mycursor.execute(sql)
mydb.commit()
return {
status: 'success'
}
I would like to successfully execute the SQL command above to the remote RDS database. But I keep getting "Unable to import module 'lambda_function': No module named 'mysql'"