Write CSV into Amazon S3 bucket without storing it on a local machine.

Sudhanshu Sharma
COOX Tech
Published in
1 min readSep 20, 2020

Due to the increasing need for analytics in every company today, exporting data to CSV is a very important feature in apps today. So in this article, I will put you through how to easily generate CSV with Node.js and csvjson and upload it to AWS S3.

To upload files to S3, we will need the aws-sdk express csvjsonpackage from npm:

npm i aws-sdk express csvjson

Now we can start writing our actual code:

Each header field specification:

1.Bucket: My Bucket name on the S3 server.

2.Key: My file path in which my CSV file will be save.

3.Body: Content of my CSV file.

4.ContentType: We will be using ‘text/csv’.

S3 upload method returns error and data in callback, where the data field contains location, bucket and key of uploaded file. For complete API reference, refer their official docs.

If you don’t get any error in the above snippet, your bucket should have the file.

I hope you found this post useful and please do let me know in case of any question or query. If you like this post, you can clap for it or follow me on Medium for my latest posts or on Twitter.

GitHub: Checkout the complete code here

--

--

Sudhanshu Sharma
COOX Tech

Full Stack Developer, Happy to share whatever I learn. Get a friend link by messaging me Instagram: sudhanshu__coder Email: sudhanshusharma647@gmail.com 🇮🇳