简体   繁体   中英

No module named 'MySQLdb' in AWS Lambda function

this is my lambda function:

import pandas as pd
import numpy as np
from sqlalchemy import create_engine


def lambda_handler(event, context):
   
    data = [10,20,30,40,50,60]
    df = pd.DataFrame(data, columns=['Numbers'])
    
    engine = create_engine('mysql://admin:blabla@database-1.blabla.eu-west 1.rds.amazonaws.com/blablabla')

    df.to_sql('list_last_update_lambda', con=engine, if_exists='replace')
    
    return()

Two layers installed:

在此处输入图像描述

log:

"errorMessage": "No module named 'MySQLdb'", "errorType": "ModuleNotFoundError"

Can anybody help? Thanks!

Found the answer:

import pandas as pd
import numpy as np
from sqlalchemy import create_engine
import pymysql

def lambda_handler(event, context):
   
    data = [10,20,30,40,50,60]
    df = pd.DataFrame(data, columns=['Numbers'])
    
    engine = create_engine('mysql+pymysql://admin:blabla@database-1.blabla.eu-west 1.rds.amazonaws.com/blablabla')

    df.to_sql('list_last_update_lambda', con=engine, if_exists='replace')
    
    return()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM