gpt4 book ai didi

node.js - AWS Timestream - SDK V3 Nodejs,TimestreamWriteClient.send() - TypeError : command. resolveMiddleware 不是函数。如何解决这个问题?

转载 作者:行者123 更新时间:2023-12-05 01:50:10 29 4
gpt4 key购买 nike

我在 NodeJs 14.x 中有以下 lambda 函数,使用 AWS SDK V3 进行时间流插入过程:

'use strict'
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-timestream-write/index.html
const { TimestreamWriteClient } = require("@aws-sdk/client-timestream-write")

const client = new TimestreamWriteClient({ region: process.env.region })


module.exports.fnPostElectricityTimestream = async event => {
try {
console.log('🚀 START fnPostElectricityTimestream')

const jsonBody = event
const topic = jsonBody.topic
const arrTopic = topic.split('/')
let dbName = arrTopic[4]
dbName = 'smaj56g' //Test

const currentTime = Date.now().toString() // Unix time in milliseconds get jsonBody.e_timestamp
const e_timestamp = (jsonBody.e_timestamp)*1000

const dimensions = [{
'Name': 'n',
'Value': 'v'
}]
const e_ch_1 = {
'Dimensions':dimensions,
'MeasureName': 'e_ch_1',
'MeasureValue': '[1,2,3]',
'MeasureValueType': 'VARCHAR',
'Time': currentTime
}
const records = [e_ch_1]
const params = {
DatabaseName: dbName,
TableName:'e_ch_1_v_w',
Records: records
}
const data = await client.send(params);
console.log('data', data)

return {
message: ''
}
} catch (error) {
console.log('🚀 fnPostElectricityTimestream - error.stack:', error.stack)
return {
message: error.stack
}
}
}

当我运行 lambda 时,这是我收到的消息:

2022-08-12T14:58:39.496Z    e578a391-06b4-48a9-9f9d-9440a373c19e    INFO    🚀 fnPostElectricityTimestream - error.stack: TypeError: command.resolveMiddleware is not a function
at TimestreamWriteClient.send (/var/task/node_modules/@aws-sdk/smithy-client/dist-cjs/client.js:13:33)
at Runtime.module.exports.fnPostElectricityTimestream [as handler] (/var/task/src/ElectricityTimestream/fnPostElectricityTimestream.js:38:31)
at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:73:25)

const data = await client.send(params) 有一些东西。我正在关注 this documentation 中的 asyncawait 代码.

如何解决这个问题?

最佳答案

您当前的插入代码有误。为了在TimeStream 中写入记录,您需要使用WriteRecordsCommand 命令。引用doc为了更好地理解。示例代码:

import { TimestreamWriteClient, WriteRecordsCommand } from "@aws-sdk/client-timestream-write";

const client = new TimestreamWriteClient({ region: "REGION" }); //your AWS region
const params = {
DatabaseName: dbName, //your database
TableName: tableName, //your table name
Records: records //records you want to insert
}

const command = new WriteRecordsCommand(params);
const data = await client.send(command);

关于node.js - AWS Timestream - SDK V3 Nodejs,TimestreamWriteClient.send() - TypeError : command. resolveMiddleware 不是函数。如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73336268/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com