[英]Put records in batches to kinesis firehose using aws lambda in java
[英]AWS Kinesis Firehose: how to put multiple files containing JSONs using aws cli & bash
我有 >100 个文件,其中每一行都是一个 json。 它看起来像这样(没有逗号和没有 []):
{"one":"one","two":{"tree":...}}
{"one":"one","two":{"tree":...}}
...
{"one":"one","two":{"tree":...}}
为了能够使用 aws firehose put-record-batch,文件需要采用以下格式:
[
{
"Data": blob
},
{
"Data": blob
},
...
]
我想将所有这些文件从终端放到 aws Firehose 中。
我正在寻找编写一个如下所示的 shell 脚本:
for file in files
do
aws firehose put-record-batch --delivery-stream-name <name> --records file://$file
done
所以有2个问题:
for file in *.json;
do
jq -s . "${file}" >${file}.tmp && mv ${file}.tmp $file
done
这将读取当前目录中的所有 json 文件并将其更改为所需的格式并保存到文件中。
或者,如果您没有jq
这里是使用python's
json 模块的替代方法。
for file in *.json;do
while read line ; do
echo $line | python -m json.tool
done < ${file} |awk 'BEGIN{print "["}{print}END{print "]"}'
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.