How to send data to Kinesis Data Firehose using the AWS JavaScript SDK v3?

0

NOTE: I cross-posted to StackOverflow here.

I am trying to send JSON data to Kinesis Data Firehose, where it will be delivered to an S3 bucket.

It works with AWS SDK v2:

const AWS = require('aws-sdk');

// Full config not shown.
AWS.config.update({
  region: 'us-east-1'
});

const Firehose = new AWS.Firehose();
const params = {
  DeliveryStreamName: 'MY-STREAM-NAME',
  Record: {
    Data: JSON.stringify({
      key: "test",
      value: "hello world"
    }),
  },
};
    
Firehose.putRecord(params, () => {});

The Data value I see in the HTTP traffic is eyJrZXkiOiJ0ZXN0IiwidmFsdWUiOiJoZWxsbyB3b3JsZCJ9 which is exactly my payload, stringified and Base64-encoded.

However, it does not work with AWS SDK v3:

import { FirehoseClient, PutRecordCommand } from "@aws-sdk/client-firehose";

// Full config not shown.
const config = {
  region: "us-east-1"
};

const client = new FirehoseClient(config);
const input = {
  DeliveryStreamName: "MY-STREAM-NAME",
  Record: {
	Data: JSON.stringify({
	  key: "test",
	  value: "hello world"
	})
  },
};

const command = new PutRecordCommand(input);
const response = await client.send(command);
console.log(response);

Now when I check the HTTP traffic, the Data value is AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA which is clearly wrong.

I have checked lots of documentation and examples (1, 2, 3), but they are not helpful.

How do I send JSON data to Firehose using AWS SDK v3?

Sam
已提问 8 个月前578 查看次数
1 回答
0

Hi, From the description of your question it seems if you're using Node.js as the runtime environment. If not, which runtime environment are you utilising here? It seems that the issue might be of encoding as message is being read by firehose but it is not returning the correct value.

AWS
支持工程师
Ayush_T
已回答 8 个月前
  • I am using vanilla javascript in browser.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则