Greengrass error-'module' object has no attribute 'lambda_handler'

0

Hi There,

I am trying to get the example code (to extract MQTT topic and message) run on my Raspberry pi.

CODE-
import greengrasssdk
import logging

client = greengrasssdk.client('iot-data')

OUTPUT_TOPIC = 'test/topic_results'

def get_input_topic(context):
try:
topic = context.client_context.custom['subject']
except Exception as e:
logging.error('Topic could not be parsed. ' + repr(e))
return topic

def get_input_message(event):
try:
message = event['test-key']
except Exception as e:
logging.error('Message could not be parsed. ' + repr(e))
return message

def function_handler(event, context):
try:
input_topic = get_input_topic(context)
input_message = get_input_message(event)
response = 'Invoked on topic "%s" with message "%s"' % (input_topic, input_message)
logging.info(response)
except Exception as e:
logging.error(e)

client.publish(topic=OUTPUT_TOPIC, payload=response)  

return  

I am running this code as a on demand function and greengrasssdk included in the uploaded package.

When I run this I get the following error-

[FATAL]-lambda_runtime.py:356,Failed to initialize Lambda runtime due to exception: 'module' object has no attribute 'lambda_handler'

Please suggest what I may be doing wrong.

Thank you in advance.

Ashish Shukla

asked 5 years ago362 views
1 Answer
0

Hi AshishShukia,

Are you able to edit your Lambda function inline, see step 8?
https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html

Thanks,
KR-AWS

AWS
KR-AWS
answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions