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?
This works:
Data: new TextEncoder().encode(JSON.stringify({key: "test", value: "hello world" }))
(from my question on StackOverflow).