I am trying to create the following architecture on AWS. AWS architecture
I have 3 devices connected to Iot core:
-Thermometer
-Air conditioner
-Lambda function
Thermometer should send the temperature every 5 seconds to the Core, then the telemetry is sent to Kinesis stream and to Kinesis Analytics.
Here is the query who groups data arriving in 60 sec windows.
Query :
CREATE OR REPLACE STREAM "TEMPSTREAM" (
"avg_temp" BIGINT NOT NULL,
"dateTime" TIMESTAMP,
"sender_id" VARCHAR(64));
CREATE OR REPLACE PUMP "SAMPLEPUMP" AS
INSERT INTO "TEMPSTREAM" ("avg_temp","dateTime","
SELECT STREAM AVG("temperature") as "avg_temp",ROWTIME,"sender"
FROM "SOURCE_SQL_STREAM_001"
GROUP BY "sender",STEP("SOURCE_SQL_STREAM_001".ROWTIME BY INTERVAL '60' SECOND)
having AVG("temperature")>=27;
It produces the Average of the temperature then sends it to Lambda function.
This function just connects to IoT Core and sends a message on a topic. Air conditioner is subscribed to this same topic waiting for a message to turn on or off.
Problem
It's almost all working fine, the problem is that even if the query produces just one result a minute, Lambda function recives it more than once a minute as you can see from the screenshot below:
Lambda code is the same of the Kinesis Output Template