timestream/src-lambda-write-to-timestream/app.py [146:214]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        payload_records = dict_to_records(input_transformed)
        logger.info("Payload records: % s" %
                    json.dumps(payload_records))

        # Write records to Amazon Timestream table TABLE_NAME_TELEMETRY
        timestream.write_records(DatabaseName=DB_NAME,
                                 TableName=TABLE_NAME_TELEMETRY,
                                 CommonAttributes={
                                     'Dimensions': dimensions,
                                     'MeasureValueType': 'DOUBLE',
                                     'Time': str(int(time() * 1000)),
                                     'TimeUnit': 'MILLISECONDS'
                                 },
                                 Records=payload_records)

        # Iterate over each of gateways in LoRaWAN metadata
        for gateway_metadata in metadata["Gateways"]:
            dimensions_per_gateway = dimensions.copy()

            # Add GatewayEUI to dimensions
            dimensions_per_gateway.append(
                {'Name': "GatewayEui", 'Value': str(gateway_metadata["GatewayEui"])})
            logger.info("Dimensions for gateway: %s" %
                        json.dumps(dimensions_per_gateway))

            # Create Amazon Timestream records
            records_per_gateway = dict_to_records({
                "Rssi": gateway_metadata["Rssi"],
                "Snr": gateway_metadata["Snr"],
                "Frequency": metadata["Frequency"],
                "DataRate": metadata["DataRate"]

            })

            # Write records to Amazon Timestream table TABLE_NAME_METADATA
            timestream.write_records(DatabaseName=DB_NAME,
                                     TableName=TABLE_NAME_METADATA,
                                     CommonAttributes={
                                         'Dimensions': dimensions_per_gateway,
                                         'MeasureValueType': 'DOUBLE',
                                         'Time': str(int(time() * 1000)),
                                         'TimeUnit': 'MILLISECONDS'
                                     },
                                     Records=records_per_gateway)

        # Define the output of AWS Lambda function
        result = {
            "status": 200
        }
        logger.info(result)
        return result

    except Exception as exp:

        exception_type, exception_value, exception_traceback = sys.exc_info()
        traceback_string = traceback.format_exception(
            exception_type, exception_value, exception_traceback)

        # Define the error message

        result = {
            "errorType": exception_type.__name__,
            "errorMessage": str(exception_value),
            "stackTrace": traceback_string
        }
        logger.error("Exception during execution: %s" % json.dumps(result))

        # Finish AWS Lambda processing with an error
        raise exp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



timestream_for_transform_binary_payload/src-lambda-write-to-timestream/app.py [160:228]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        payload_records = dict_to_records(input_transformed)
        logger.info("Payload records: % s" %
                    json.dumps(payload_records))

        # Write records to Amazon Timestream table TABLE_NAME_TELEMETRY
        timestream.write_records(DatabaseName=DB_NAME,
                                 TableName=TABLE_NAME_TELEMETRY,
                                 CommonAttributes={
                                     'Dimensions': dimensions,
                                     'MeasureValueType': 'DOUBLE',
                                     'Time': str(int(time() * 1000)),
                                     'TimeUnit': 'MILLISECONDS'
                                 },
                                 Records=payload_records)

        # Iterate over each of gateways in LoRaWAN metadata
        for gateway_metadata in metadata["Gateways"]:
            dimensions_per_gateway = dimensions.copy()

            # Add GatewayEUI to dimensions
            dimensions_per_gateway.append(
                {'Name': "GatewayEui", 'Value': str(gateway_metadata["GatewayEui"])})
            logger.info("Dimensions for gateway: %s" %
                        json.dumps(dimensions_per_gateway))

            # Create Amazon Timestream records
            records_per_gateway = dict_to_records({
                "Rssi": gateway_metadata["Rssi"],
                "Snr": gateway_metadata["Snr"],
                "Frequency": metadata["Frequency"],
                "DataRate": metadata["DataRate"]

            })

            # Write records to Amazon Timestream table TABLE_NAME_METADATA
            timestream.write_records(DatabaseName=DB_NAME,
                                     TableName=TABLE_NAME_METADATA,
                                     CommonAttributes={
                                         'Dimensions': dimensions_per_gateway,
                                         'MeasureValueType': 'DOUBLE',
                                         'Time': str(int(time() * 1000)),
                                         'TimeUnit': 'MILLISECONDS'
                                     },
                                     Records=records_per_gateway)

        # Define the output of AWS Lambda function
        result = {
            "status": 200
        }
        logger.info(result)
        return result

    except Exception as exp:

        exception_type, exception_value, exception_traceback = sys.exc_info()
        traceback_string = traceback.format_exception(
            exception_type, exception_value, exception_traceback)

        # Define the error message

        result = {
            "errorType": exception_type.__name__,
            "errorMessage": str(exception_value),
            "stackTrace": traceback_string
        }
        logger.error("Exception during execution: %s" % json.dumps(result))

        # Finish AWS Lambda processing with an error
        raise exp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



