How to read values from a csv file hosted on AWS S3 using Serverless
A step by step walkthrough on reading values from a CSV document hosted on AWS using Typescript & Serverless.
The following tutorial walks you through how to gather a csv file from AWS S3 and process it in a way that allows you to read its values using Typescript & Serverless.
We have provided our open source project GitHub repository in the link below to help you quick start the process.
Please note that this tutorial does not walk you through how to setup Serverless to work with AWS.
Step One: Install Dependencies
Open terminal, set the current directory to your serverless project and add csv-parser using the following line:
yarn add csv-parser
If you require to add AWS to your typescript and serverless project, add the dependency using the following line:
yarn add aws-sdk
Step Two: Gather the CSV file
In your Typescript & Serverless project, create a new file called getCSVFile.ts and copy the code found below into your file.
Please replace YOUR_TYPE with the structure type for your csv file.
Step Three: Read Values
If you call the function created in Step Two with the name of the bucket hosting your file, along with the file path (key) it will return an array of YOUR_TYPE and can be accessed like any other object.