3

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'"

1 Answer 1

1

When deploying a Python function to AWS Lambda, you need to bundle your dependencies with your Python file(s).

If your function depends on libraries other than the SDK for Python (Boto 3), install them to a local directory with pip, and include them in your deployment package.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.