我们正在通过Kinesis Stream处理数据(记录)到Kinesis Firehose,然后将数据输出到S3存储桶中的文件。
但是,目前,我们的输出文件中的所有记录都在同一行,但我们希望将每条记录分开,以便它们在各自的行上。
而不是像:
Store1, 100, Broccoli
Store1, 101, Avocado
Store1, 102, Apple
目前看起来像:
Store1, 100, BroccoliStore1, 101, AvocadoStore1, 102, Apple
以下是我们的CloudFormation模板:
Resources:
MyBucket:
Type: AWS::S3::Bucket
MyStream:
Type: AWS::Kinesis::Stream
Properties:
Name: my-stream
RetentionPeriodHours: 24
ShardCount: 5
MyFirehose:
Type: AWS::KinesisFirehose::DeliveryStream
Properties:
DeliveryStreamName: my-firehose
DeliveryStreamType: KinesisStreamAsSource
KinesisStreamSourceConfiguration:
KinesisStreamARN:
Fn::Sub: "${MyStream.Arn}"
RoleARN:
Fn::Sub: "${MyRole.Arn}"
S3DestinationConfiguration:
BufferingHints:
IntervalInSeconds: 60
SizeInMBs: 50
CompressionFormat: UNCOMPRESSED
Prefix: concessions/
BucketARN:
Fn::Sub: "${MyBucket.Arn}"
RoleARN:
Fn::Sub: "${MyRole.Arn}"
我们如何添加行分隔符以便记录显示在各自的行上?
答案 0 :(得分:2)
谁来喂你的运动流应该添加' \ n'在末尾。 请参阅下面的Java示例:
PutRecordRequest putRecordRequest = new PutRecordRequest();
putRecordRequest.setFirehoseName("incoming-stream");
String data = "some data" + "\n"; // add \n as a record separator
Record record = new Record();
record.setData(ByteBuffer.wrap(data.getBytes(StandardCharsets.UTF_8)));
putRecordRequest.setRecord(record);
firehoseClient.putRecord(putRecordRequest);
请参阅source.