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
asked 7 months ago536 views
1 Answer
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
SUPPORT ENGINEER
Ayush_T
answered 7 months ago
  • I am using vanilla javascript in browser.

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