我配置了 Amplify 应用程序,并尝试使用命令在本地测试 AWS Lambda 函数amplify mock function,但出现错误,指出requests未找到该模块,如下所示。
> amplify mock function
? Select the function to mock MLFunction
? Provide the path to the event JSON object relative to C:\Users\warre\OneDrive\Documents\College\Msc\FinalYearProject\AWS\Amplify_Tutorial\amplify-app\amplify\backend\function\MLFunction src/event.json
Ensuring latest function changes are built...
Starting execution...
Traceback (most recent call last):
File "C:\Users\warre\.amplify\lib\amplify-python-function-runtime-provider\shim\shim.py", line 44, in <module>
main(sys.argv[1:])
File "C:\Users\warre\.amplify\lib\amplify-python-function-runtime-provider\shim\shim.py", line 22, in main
spec.loader.exec_module(handlerModule)
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\warre\OneDrive\Documents\College\Msc\FinalYearProject\AWS\Amplify_Tutorial\amplify-app\amplify\backend\function\MLFunction\src\index.py", line …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Lambda 函数连接到 DocumentDB。
我已经按照本教程配置了 DocumentDB ,并且可以通过 cloud9 命令提示符访问它。
documentDB 集群是两个安全组的一部分。第一个安全组称为 vpc默认安全组demoDocDB,第二个称为defaultvpc 默认安全组。
demoDocDB用于将请求从 cloud9 实例转发到运行我的 documentDB 数据库的端口 27017 的入站规则。
安全组的入站规则defualt指定所有流量、所有端口范围及其自身的来源。VPC ID 是默认的 VPC 设置。
在 lambda 中编辑 VPC 详细信息时,我输入了:
defaultVPC 的安全组该函数在写入数据库时工作了两次,其余时间都超时了,Lambda 函数的超时时间为 2 分钟,但在达到该超时时间之前,它将抛出超时错误。
[ERROR] ServerSelectionTimeoutError: MY_DATABASE_URL:27017: [Errno -2] Name or service not known
Run Code Online (Sandbox Code Playgroud)
下面的代码片段是尝试执行的代码,该函数永远不会print("INSERTED DATA")在插入语句期间达到超时。
def getDBConnection():
client = pymongo.MongoClient(***MY_URL***)
##Specify the database to …Run Code Online (Sandbox Code Playgroud)