Thing To Dynamo Help

0

Hi, I have some raw CSV data coming in from my THING. I created a rule but am having trouble parsing the data to my Dynamo DB. I can write all to one Type, but not multiple or separately. I want to break out every Data Point to a different Item, but I cant seem to figure out the correct syntax. Can someone please advise?

My Thing Data Via Subscription: [ "2024-06-24 10h47m47s45ms", "24001010001220", "WreckRoom", "LIFETIME", "3423423", "LTMN00001", "Bloomington", "MN", "RedFit Room", "SaunaV01.0", "0", "32.0", "0", "0", "0", "0", "0", "0", "0", "0" ]

Dynamo DB to one Item: { "Key": { "S": "dDataMain" }, "payload": { "L": [ { "S": "2024-06-24 10h47m47s45ms" }, { "S": "24001010001220" }, { "S": "WreckRoom" }, { "S": "LIFETIME" }, { "S": "3423423" }, { "S": "LTMN00001" }, { "S": "Bloomington" }, { "S": "MN" }, { "S": "RedFit Room" }, { "S": "SaunaV01.0" }, { "S": "0" }, { "S": "32.0" }, { "S": "0" }, { "S": "0" }, { "S": "0" }, { "S": "0" }, { "S": "0" }, { "S": "0" }, { "S": "0" }, { "S": "0" } ] } }

1 Answer
0

Hi Brent,

To parse your CSV data and store each data point as a separate item in DynamoDB, follow these steps:

  1. Create an IoT Rule:

    • Set up a rule to trigger a Lambda function when data is received.
  2. Lambda Function:

    • Write a Lambda function to process the data and insert each data point into DynamoDB. Here's a concise Python example:
    import json
    import boto3
    
    dynamodb = boto3.client('dynamodb')
    
    def lambda_handler(event, context):
        payload = event['payload']
        for i, data_point in enumerate(payload):
            item = {
                'Key': {'S': f'dDataMain-{i}'},
                'DataPoint': {'S': str(data_point)}
            }
            dynamodb.put_item(TableName='YourDynamoDBTableName', Item=item)
        return {'statusCode': 200, 'body': 'Data points written to DynamoDB successfully'}
  3. Deploy and Test:

    • Deploy the Lambda function.
    • Update the IoT rule to invoke the Lambda.
    • Test with your CSV data to ensure each point is stored as a separate item.

I'm glad to help.

profile picture
EXPERT
answered 3 months ago
  • Thank you very much Victor. Much appreciated!!!

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