简体   繁体   English

将代码上传到 AWS lambda 错误 Runtime.ImportModuleError

[英]Upload code to AWS lambda error Runtime.ImportModuleError

I am trying to put this scraping code on AWS Lambda, when i try to test the code i get the following error:我正在尝试将此抓取代码放在 AWS Lambda 上,当我尝试测试代码时出现以下错误:

"errorMessage": "Unable to import module 'lambda_function': No module named 'lambda_function'",
  "errorType": "Runtime.ImportModuleError"

The code:编码:

from datetime import datetime
from functions import MultiplePageScraper, CleanTable, upload_unique, pages
from sqlalchemy import create_engine
now = datetime.now()
date = now.date()

# Credentials:
host = xxxxx
user = "admin"
password = xxxxx
port = 3306
database = "vehicles"
# Create connection
mydb = create_engine("mysql+pymysql://" + user + ':' + password + '@' + host + ':' + str(port) + '/' + database , echo=False)

# Target Url :
URL = "https://www.usedcars.co.ke/nairobi/cars-for-sale?page="

def lambda_handler(event, context):
    # Retrive the data and clean it
    page_count = pages(URL)
    data = MultiplePageScraper(URL, int(page_count))
    clean_data = CleanTable(data)
    # Check for duplicates scraped Vs Database
    upload_data = upload_unique(clean_data, mydb)
    # Upload data to RDS database
    if upload_data.shape[0] > 1:
        upload_data.to_sql(name='CARS', con=mydb, if_exists = 'append', index=False)
        print(f'Uploaded {upload_data.shape[0]} unique rows to the database!')
    else:
        print('No new cars to upload.')

I have no idea what the error means, any one can help?我不知道错误是什么意思,任何人都可以帮忙吗?

By default, a new python lambda function will look for lambda_function.py file and call lambda_handler method:默认情况下,新的 python lambda function 将查找lambda_function.py文件并调用lambda_handler方法:

在此处输入图像描述

You can change it using the runtime settings for your function.您可以使用 function 的运行时设置来更改它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Lambda Python 错误 - Runtime.ImportModuleError - AWS Lambda Python error - Runtime.ImportModuleError 如何解决“Runtime.ImportModuleError”在 AWS lambda 中没有名为“mysql”的模块? - How to solve “Runtime.ImportModuleError” No module named 'mysql' in AWS lambda? AWS Lambda Docker 自定义 Python 库 (Runtime.ImportModuleError) - AWS Lambda Docker Custom Python Library (Runtime.ImportModuleError) AWS Lambda代码无法从S3导入Depdendencies - Runtime.ImportModuleError - AWS Lambda Code Unable to Import Depdendencies from S3 — Runtime.ImportModuleError 我需要帮助解决 AWS Lambda 中的 Runtime.ImportModuleError - I need help resolving a Runtime.ImportModuleError in AWS Lambda Runtime.ImportModuleError:无法导入模块(lambda) - Runtime.ImportModuleError: Unable to import module (lambda) AWS Lambda python 错误:Runtime.ImportModuleError:无法导入模块“app”:无法从“pyparsing”导入名称“operatorPrecedence” - AWS Lambda python Error: Runtime.ImportModuleError: Unable to import module 'app': cannot import name 'operatorPrecedence' from 'pyparsing' AWS "Hello World" Python Lambda 导致 Runtime.ImportModuleError: "Unable to import module" - AWS "Hello World" Python Lambda results in Runtime.ImportModuleError: "Unable to import module" Runtime.ImportModuleError: Unable to import module 'testsdk': No module named 'jsonpickle' with Python script using AWS Lambda - Runtime.ImportModuleError: Unable to import module 'testsdk': No module named 'jsonpickle' with Python script using AWS Lambda Lambda Python 依赖包错误 Runtime.ImportModuleError:无法导入模块“lambda_function”:没有名为“surveys”的模块 - Lambda Python Dependency Package ERROR Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'surveys'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM