简体   繁体   English

从云Lambda函数调用本地AWS Lambda函数

[英]Invoking local AWS Lambda function from a cloud Lambda function

I made 2 Lambda functions (LambdaFunction_1 and LambdaFunction_2). 我制作了2个Lambda函数(LambdaFunction_1和LambdaFunction_2)。 I have deployed LambdaFunction_1 on my AWS-Greengrass core which is RaspberryPi 3 to be the local lambda function. 我已经在我的AWS-Greengrass核心上部署了LambdaFunction_1,它是RaspberryPi 3的本地lambda函数。 I want to invoke LambdaFunction_1 from LambdaFunction_2. 我想从LambdaFunction_2调用LambdaFunction_1。 The local lambda function can't be invoked for strange reason that I can't understand. 由于我无法理解的奇怪原因,无法调用本地lambda函数。

To deploy the local lambda function (LambdaFunction_1) I have to upload a zip file containing the python file of the code and the greengrasssdk. 要部署本地lambda函数(LambdaFunction_1),我必须上传一个包含代码的python文件和greengrasssdk的zip文件。 Importing this greengrasssdk in the code makes it unable to be invoked! 在代码中导入此greengrasssdk使其无法被调用!

This is the code for LAmbdaFunction_2 which is on cloud: 这是在云上的LAmbdaFunction_2的代码:

import json
import boto3
invokeLam = boto3.client('lambda')
def lambda_handler(event, context):   
payload = {'test-key': 'Hi, you have been invoked!'}
response_F1 = invokeLam.invoke(
                               FunctionName = 'LambdaFunction_1', 
                               InvocationType = 'RequestResponse', 
                               LogType='None', 
                               Payload = json.dumps(payload) 
                              )
data_F1 = response_F1['Payload'].read()
print (data_F1)
return

This is the code of LambdaFunction_1 which is deployed on greengrass core: 这是部署在greengrass核心上的LambdaFunction_1的代码:

import json
import greengrasssdk
def function_handler(event, context):
    print (event)
    return 'Hello From Function 1'

The output should be "Hello From Function 1" in the log file of Function 2. But the response is {"errorMessage": "Unable to import module 'LambdaFunction_1'"} 函数2的日志文件中的输出应为“Hello From Function 1”。但响应为{“errorMessage”:“无法导入模块'LambdaFunction_1'”}

BUT: when I remove (import greengrasssdk) line from the code of function one it works perfectly. 但是:当我从函数1的代码中删除(import greengrasssdk)行时,它完美地工作。 Is this problem logical? 这个问题合乎逻辑吗?

I found the solution that I have to import two libraries in LambdaFunction_1 beside greengrasssdk which are: 1- greengrass_ipc_python_sdk 2- greengrass_common 我找到了我必须在greengrasssdk旁边的LambdaFunction_1中导入两个库的解决方案:1- greengrass_ipc_python_sdk 2- greengrass_common

I got the answer by viewing the log files of LambdaFunction_1 as advised by @Stargazer 我通过查看@Stargazer建议的LambdaFunction_1的日志文件得到了答案

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

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