• About Me
  • Projects
  • WebApp
  • Archive

Barnaby Baron. Exploring AWS.

  • Building a Lambda function to process a CSV when uploaded to an S3 bucket

Building a Lambda function to process a CSV when uploaded to an S3 bucket

2024-05-02 3 min read Projects Barny Baron

Journey: 📊 Community Builder 📊

Subject matter: Building on AWS

Task: Building a Lambda function to process a CSV when uploaded to an S3 bucket.

This project is about serverless automation.

Using the 6 Pillars of the AWS Well-Architected Framework, Performance Efficiency will be achieved in this build.

I will be setting up a Lambda function which triggers automatically whenever a CSV file is uploaded to an Amazon S3 bucket. The Lambda function reads the CSV file, calculates an average of the contents and then prints the calculation to a Cloudwatch log.

Efficiency

Credit: This serverless architecture was created using guidance from Arsh on Medium Here

What did I use to build this environment?

  • AWS Lambda [with Panda layers]
  • Amazon S3
  • Amazon Cloudwatch
  • AWS Management Console
  • IAM

What is built?

  • A new S3 bucket
  • A configured, layered Lambda function using Python

Using the principle of least privilege:

Taken from the AWS documentation Here:

“The principle of least privilege states that identities should only be permitted to perform the smallest set of actions necessary to fulfill a specific task.”

To obtain the correct Lambda Permission for this, I used some further documentation Here

This task involved using initial Python code to import and print the CSV file contents. Once this was working, I then amended the Python code to generate an average score against the CSV dataset.

Once I had configured all of the areas, the Lambda function successfully calculated the average and printed it to the Cloudwatch logs.

Some of the highlights…

IAM Lambda Role Permissions:

IAM

Lambda function:

Function

Initial Lambda code:

Code

Initial Lambda test:

Test

Cloudwatch output:

Cloudwatch

Enhanced Lambda code:

Code

Lambda layer:

Layer

New Cloudwatch output:

Cloudwatch

My interpretation of the architecture:

Architecture

I hope you have enjoyed the article, I enjoyed the build!

Cloud

Community Builder Serverless Lambda S3
Latest posts
  • Designing a Formula 1 Race Track and gaining insights from Amazon Nova
  • Year 2 - AWS Community Builder
  • Troubleshooting an EKS Pod creation error - Persistent Volume Controller Failed Binding
  • Building an EKS cluster and mounting an S3 bucket within a pod using the CSI Driver
  • Sopra Steria Merch Delivery!
  • AWS Community Builders Application Window!
  • Building a VPC and provisioning an EC2 instance using Modules!
Categories
  • AWS News (84)
  • Projects (29)
  • Exploring (19)
  • Troubleshooting (10)
  • General (8)
  • Quotes (5)
  • Video (3)
Social media
Archive
© 2025 by Barny Baron
Powered by Bilberry Hugo Theme