Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

read from s3 bucket nodejs

const aws = require('aws-sdk');
const s3 = new aws.S3();

const params = {Bucket: 'myBucket', Key: 'myJson.json'};
await s3.getObject(params).promise()
Comment

get s3 bucket file with file link on nodejs

// Note the s3 file must have access policy applied
/*
When the Http Stream instance is destroyed, the 'close' event will be emitted. Because Http2Stream is an instance of stream.Duplex, the 'end' event will also be emitted if the stream data is currently flowing. The 'error' event may also be emitted if httpstream.destroy() was called with an Error passed as the first argument.
*/


const http = require('http');
const csv = require('csv-parser')
var arr = [];
var count = 0
http.get('some s3 file path', (res) => {
//   console.log('statusCode:', res.statusCode);
//   console.log('headers:', res.headers);
    res.pipe(csv()).on('data',  (d) => {
        count++;
        console.log('count : ',count)
        arr.push(d);


        // this is watermark or minimum csv data requirement
        if(arr.length > 10) {
            res.destroy()
             a(arr)
        } else {
            console.log("no data")
        }

    });

  res.on('close', (d) => {
    console.log("
 Data : 
", arr.length);
  });

  res.on('error', (e) => {
    console.error(e);
  })

});
Comment

PREVIOUS NEXT
Code Example
Javascript :: bootstrap carousel click event next previous 
Javascript :: Javascript console log a int 
Javascript :: apa itu this pada javascript 
Javascript :: remove trailing slash javascript 
Javascript :: javascript remove last character in a string 
Javascript :: elasticsearch field not exists 
Javascript :: remove element from an array 
Javascript :: how to find length of array js 
Javascript :: check if body has class javascript 
Javascript :: get the value of a checkbox jquery 
Javascript :: change value of key in array of objects javascript 
Javascript :: javascript skip default parameter 
Javascript :: how to make jtextarea scrollable 
Javascript :: react open url with button 
Javascript :: js import export es5 
Javascript :: js get bytearray from file 
Javascript :: how to add jquery in js file 
Javascript :: angular cli path environment variable 
Javascript :: angular access current scope from console 
Javascript :: javascript string array sort alphabetically 
Javascript :: get cookie value in javascript 
Javascript :: reverse a linked list javascript 
Javascript :: We often use anonymous functions as arguments of other functions. For example: 
Javascript :: how to use compare password in node js 
Javascript :: how to get value from input field in javascript 
Javascript :: javascript round to 2 digits 
Javascript :: javascript reduce array of objects 
Javascript :: how to delete a variable in js 
Javascript :: sequelize test connection 
Javascript :: laravel csrf token ajax post 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =