How to read values from a csv file hosted on AWS S3 using Serverless

Oscar de la Hera Gomez
Four flowers that represent AWS Lambda, AWS S3, Typescript & Serverless. Beneath it sits the text "CSV."

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

The NPM page for the csv-parser package.

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

A screenshot of the code provided below.

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

A screenshot of the csv-parser library showing you how the results of the function above become available.

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.

Any Questions ?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details