S3から複数のjsonをdownloadして、一つのjsonにまとめたい。
※後にgraphQLで出力する
objectを配列([])で宣言して、pushする
var object = [];
const s3Client = new AWS.S3({
accessKeyId: 'fuga',
secretAccessKey: 'hoge',
region: 'ap-northeast-1'
})
function getObject(params){
s3Client.getObject(params, function(err, data){
if(err){
console.log(err, err.stack);
} else {
object.push(JSON.parse(data.Body.toString()|| "null"));
console.log(object)
fs.writeFile('speech.json', JSON.stringify(object), function(err, result){
if(err) console.log('error', err);
});
}
})
}
const params1 = {
Bucket: 'speech-dnn',
Key: 'speech.json',
}
const params2 = {
Bucket: 'speech-dnn',
Key: 'speech2.json',
}
getObject(params1);
getObject(params2);
$ node test.js
Server Now Running
$ node test.js
Server Now Running
[ { id: 1, text: ‘ 凄い技術ですね。\n’ } ]
[ { id: 1, text: ‘ 凄い技術ですね。\n’ }, { id: 2, text: ‘ びっくりしました。\n’ } ]
なるほど、これをgraphQLに入れる
※timeを追加
$ node server5.js
Express GraphQL Server Now Running On 192.168.34.10:8000/graphql
[ { id: 1, text: ‘ 凄い技術ですね。\n’, time: ‘2021/12/10 15:04:10’ } ]
[
{ id: 1, text: ‘ 凄い技術ですね。\n’, time: ‘2021/12/10 15:04:10’ },
{ id: 2, text: ‘ びっくりしました。\n’, time: ‘2021/12/10 15:04:12’ }
http://192.168.34.10:8000/graphql

OK、