Skip to content

Latest commit

 

History

History

3-aws-greengrass-telemetry

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Device health telemetry

IoT Device health telemetry data helps you monitor the performance of critical operations on your Greengrass core devices. You can use these applications to gain insights into fleet health.

To set it up,

  1. Create on-demand AWS Kinesis Data Stream and name the stream as RealmGreengrass

    DS

  2. Open the Amazon EventBridge console, and choose Create rule.

  3. Under Name and Description, enter a name as RealmGreengrassHealthCheck and a description for the rule.

  4. Under Select Event bus, keep the default option.

  5. Under the Creation method, Select Use Pattern Form.

    Pattern

  6. For Event Source, choose AWS Services, For AWS Service, choose Greengrass, For Event type, select Greengrass Telemetry Data.

  7. Under Select targets, configure your target. The following example uses an Amazon Kinesis.

    Target

  8. Go to Mongo Cloud, inside App Services, create an HTTP Endpoint with POST method, return type as JSON, and create a function to associate the HTTP endpoint with it and use the following sample code to create the telemetry health records in the MongoDB Collection

    exports = function ({ headers, body }, response) {
        const contentTypes = headers["Content-Type"];
        const reqBody = body;
        const serialized = reqBody.text();
        const jsonBody = JSON.parse(serialized);
        console.log(jsonBody);
        const GGIotDeviceHealthCollection = context.services.get("mongodb-atlas").db("VehicleMaintenance").collection("DeviceHealth");
        GGIotDeviceHealthCollection.insertOne(jsonBody)
            .then(result => console.log(`Successfully inserted item with _id: ${result.insertedId}`))
            .catch(err => console.error(`Failed to insert item: ${err}`))
        response.setStatusCode(200)
        const res = JSON.stringify({
            requestId: headers['X-Amz-Firehose-Request-Id']?.[0],
            timestamp: (new Date()).getTime()
        })
        response.addHeader(
            "Content-Type",
            "application/json"
        );
        response.setBody(res)
        return
    };

    Http

  9. Create an API Key in App services to use in AWS Firehose for granting access to AWS to trigger the HTTP Endpoint. ApiKey

  10. Create AWS Kinesis Data Firehose. Select source as Kinesis data stream and target as MongoDB Cloud, In Destination settings, Paste the HTTP URL in the Firehose console under MongoDB Realm webhook URL. Then use the API Key created in MongoDB Console, and paste it into API Key in the Firehose console. No data transformation is needed for this example. Select "Not enabled" in Content encoding. Firehose

  11. Configure Backup settings to send failed data to S3 buckets. Select the S3 bucket name in the dropdown to send failed events, and provide a prefix if needed. Then create the delivery stream.

  12. Hurray!! completed halfway through!! Now let's switch to Sagemaker setup.