AWS Greengrass

AWS IoT Greengrass is a service that extends AWS Cloud capabilities to local devices, making it possible to run AWS Lambda functions on edge devices. This allows you to process data locally, reducing the need for constant communication with the cloud.


You have a temperature sensor deployed in a remote location, and you want to monitor the temperature readings locally using AWS IoT Greengrass. When the temperature exceeds a certain threshold, you want to trigger a local action, such as turning on a fan or sending an alert.


Set Up AWS IoT Core:

  • Create an AWS IoT Core Thing for your temperature sensor.
  • Attach the required policies to your Thing to allow it to communicate with AWS IoT Core.

Set Up AWS IoT Greengrass:

    • Create a Greengrass group and core.
    • Add your temperature sensor Thing to the Greengrass group.
    • Deploy the Greengrass group configuration to your devices.

    Create Lambda Function:

    • Write a Lambda function in the AWS Lambda console that reads the temperature from the sensor.
    • Add logic to compare the temperature against a threshold and take action if the threshold is exceeded. For example:
    import json
    import greengrasssdk
    client = greengrasssdk.client('iot-data')
    def lambda_handler(event, context):
        temperature = event['temperature']
        threshold = 30  # Set your desired threshold
        if temperature > threshold:
            # Temperature exceeds threshold, take action
            message = "High temperature alert! Temperature is {} degrees.".format(temperature)
            client.publish(topic='temperature_alert', payload=json.dumps({'message': message}))
        return {'statusCode': 200, 'body': json.dumps('Temperature checked successfully.')}

    Configure Subscription:

    • Configure a subscription in the Greengrass group to send temperature data to the Lambda function.
    • Define a topic for communication between the temperature sensor and the Lambda function.

    Deploy and Test:

    • Deploy the updated Greengrass group configuration to your devices.
    • Simulate temperature changes or use your actual temperature sensor to trigger the Lambda function when the temperature exceeds the threshold.


    • Monitor the AWS IoT Greengrass logs to see the temperature readings and any alerts triggered by the Lambda function.

    This example demonstrates how AWS IoT Greengrass can be used to monitor a temperature sensor locally and take actions based on the sensor data without relying on constant communication with the cloud. Adjust the Lambda function and configuration based on your specific requirements and use case.

    Don’t hesitate, we are just a message away!

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Signup for our newsletter