Consider the following:
It's not clear how to format the 'Data' blob. Here's an example of what the code looks like with the data separated by tabs:
let AWS = require('aws-sdk');
let firehose = new AWS.Firehose();
let params = {
DeliveryStreamName: 'people',
// id,name,age
Records: [{Data: '4ccf6d3a-acdf-11e5-ad54-28cfe91fa8f1\tBob\tSmith'}]
};
firehose.putRecordBatch(params, (err, result) => {
console.log(err || result);
});
Here are some of the docs I have checked:
Amazon Kinesis Data Firehose can convert the format of your input data from JSON to Apache Parquet or Apache ORC before storing the data in Amazon S3. Parquet and ORC are columnar data formats that save space and enable faster queries compared to row-oriented formats like JSON.
Kinesis Data Firehose delivers your data to your S3 bucket first and then issues an Amazon Redshift COPY command to load the data into your Amazon Redshift cluster. Specify an S3 bucket that you own where the streaming data should be delivered.
Firehose automatically delivers the data to the Amazon S3 bucket or Amazon Redshift table that you specify in the delivery stream. For information about supported versions, see Supported Systems and Versions. To write data to Amazon Kinesis Streams, use the Kinesis Producer destination.
The answer is here:
http://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-format.html
Fields need to be pipe '|' separated by default. Rows should be separated by new lines.
Updated corrected code:
let AWS = require('aws-sdk');
let firehose = new AWS.Firehose();
let params = {
DeliveryStreamName: 'people',
// id,name,age
Records: [{Data: '4ccf6d3a-acdf-11e5-ad54-28cfe91fa8f1|Bob|Smith\n'}]
};
firehose.putRecordBatch(params, (err, result) => {
console.log(err || result);
});
You can also send straight JSON as long as you properly escape things and use the right COPY options. See COPY FROM JSON and JSON AS. If you use the 'auto' option for JSON AS then it's pretty flexible. If you send multiple dictionaries in one putRecordBatch, do NOT separate them with space or newlines, you can just send
{ key1: "value1", key2: 34 }{ key1: "value2", key2: 45 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With