Abdelhamied Raslan
Abdelhamied Raslan

Reputation: 21

Invoking local AWS Lambda function from a cloud Lambda function

I made 2 Lambda functions (LambdaFunction_1 and LambdaFunction_2). I have deployed LambdaFunction_1 on my AWS-Greengrass core which is RaspberryPi 3 to be the local lambda function. I want to invoke LambdaFunction_1 from LambdaFunction_2. The local lambda function can't be invoked for strange reason that I can't understand.

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. Importing this greengrasssdk in the code makes it unable to be invoked!

This is the code for LAmbdaFunction_2 which is on cloud:

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:

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

BUT: when I remove (import greengrasssdk) line from the code of function one it works perfectly. Is this problem logical?

Upvotes: 1

Views: 360

Answers (1)

Abdelhamied Raslan
Abdelhamied Raslan

Reputation: 21

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

I got the answer by viewing the log files of LambdaFunction_1 as advised by @Stargazer

Upvotes: 1

Related Questions