AWS IoT Timestream Rule Action Multi Measure Record

2

Hi, Is it possible to create a single db record with multiple measurements using IoT Greengrass Timestream rule action? I want to show 3 measurements from a device in a single row. Even though my select query has 3 measurement they are all inserted in to table as different rows.

My Timestream rule in CF template:

  TimestreamRule:
    Type: AWS::IoT::TopicRule
    Properties:
      TopicRulePayload:
        RuleDisabled: false
        Sql:
          !Join [
            '',
            [
              "SELECT cpu_utilization, memory_utilization, disc_utilization FROM 'device/+/telemetry'",
            ],
          ]
        Actions:
          - Timestream:
              DatabaseName: !Ref TelemetryTimestreamDatabase
              TableName: !GetAtt DeviceTelemetryTimestreamTable.Name
              Dimensions:
                - Name: device
                  Value: ${deviceId}
              RoleArn: !GetAtt SomeRole.Arn
              Timestamp:
                Unit: SECONDS
                Value: ${time}

My message payload:

{
  "cpu_utilization": 8,
  "memory_utilization": 67.4,
  "disc_utilization": 1.1,
  "deviceId": "asdasdasd123123123",
  "time": "1639141461"
}

Resulting records in Timestream:

| device | measure_name | time | measure_value::bigint | measure_value::double| | --- | | 61705b3f6ac7696431ac6b12 | disc_utilization | 2021-12-10 13:03:47.000000000 | - | 1.1 | | 61705b3f6ac7696431ac6b12 | memory_utilization | 2021-12-10 13:03:47.000000000 | - | 67.1 | | 61705b3f6ac7696431ac6b12 | cpu_utilization | 2021-12-10 13:03:47.000000000 | - | 12.1 |

This is not what I want. I want to have a single record including all three measurements, cpu, disc and memory. I know it is possible to do it somehow because provided sample db has multi measurement records, such as:

| hostname | az | region | measure_name | time | memory_utilization | cpu_utilization | | --- | | host-n2Rxl |eu-north-1a | eu-north-1 | DevOpsMulti-stats | 2021-12-10 13:03:47.000000000 | 40.324917071566546 | 91.85944083569557 | | host-sEUc8 |us-west-2a | us-west-2 | DevOpsMulti-stats | 2021-12-10 13:03:47.000000000 | 59.224512780289224 | 18.09011541205904 |

How can I achieve this? Please help!

Bests,

3回答
4
承認された回答

Amazon Timestream multi-measure records feature was recently released 11-29-2021 (https://aws.amazon.com/about-aws/whats-new/2021/11/amazon-timestream-scheduled-queries-multi-measure-records-magnetic-storage-writes/) and the AWS IoT Timestream action does not yet support multi-measure records. As a workaround you can trigger a Lambda function using the AWS IoT Lambda Action and use the AmazonTimestream Write API to insert your multi-measure record : https://docs.aws.amazon.com/timestream/latest/developerguide/API_WriteRecords.html

profile pictureAWS
エキスパート
Jan_B
回答済み 2年前
0

if you need have deviceid, cpu, disc and memory in same row then add add all four to the dimensions. Check out this blogpost for an example https://aws.amazon.com/blogs/database/trigger-notifications-on-time-series-data-with-amazon-timestream/

AWS
Sounavo
回答済み 2年前
  • Thanks for the answer, I guess the support for multi measure records will be available at some point of time. That's why I want to follow the best practices for the time being. I will implement a lambda function as a workaround for now.

0

For those interested in the answer, multi measurement insertion support is added to javascript-sdk with this release: 2.1036.0 https://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md#210360

By the time of writing the default available sdk version on aws lambda is 2.1001.0.

So need to be careful about the available sdk version.

回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ