我有一个运动数据流,其中 1 个分片只有一些数据,我目前正在通过订阅我的 nodejs 应用程序中的分片从中读取数据,但我无法这样做,因为它给了我这个错误: -
Error: TypeError: Cannot read properties of undefined (reading 'Symbol(Symbol.asyncIterator)')
这是我在下面编写的代码:-
const {
KinesisClient,
SubscribeToShardCommand,
RegisterStreamConsumerCommand,
} = require("@aws-sdk/client-kinesis");
const kinesis = new KinesisClient({ region: "ap-south-1" });
const streamName = "<my-stream-name>"
const shardId = "<my-shardid>";
const readFromShard = async () => {
const command = new SubscribeToShardCommand({
StreamName: streamName,
ConsumerARN: `<my-consumer-arn>`,
ShardId: shardId,
StartingPosition: {
Type: "LATEST",
},
});
try {
const response = await kinesis.send(command);
const subscriptionArn = response.EventStream;
console.log("Subscribed to shard:", shardId);
// Handle the received records
for await (const record of response.Records) {
console.log(record);
// const payload = Buffer.from(record.Data).toString("utf-8");
console.log("Received data:", payload);
}
// Subscription is closed, handle it as needed
console.log("Subscription closed:", subscriptionArn);
} catch (error) {
console.error("Error:", error);
}
};
readFromShard();
解决此错误的任何帮助将不胜感激。谢谢。