Lambda Function Setup

Configure smart serverless functions to handle file uploads, deduplication logic, and cleanup—powering the core of our efficient, user-aware storage system.

We will now set up the core Lambda functions that power the file deduplication logic. These serverless functions are the brain of the project — handling file validation, deduplication checks, S3 operations, and user tracking in DynamoDB.

There are two main Lambda functions in this project:

  1. Upload Handler — triggered when a user uploads a file

  2. Delete Handler — triggered when a user deletes/unlinks a file


Step 1: Create the Upload Lambda Function

  1. Go to AWS Console → Lambda

  2. Click Create Function

  3. Select:

    • Author from scratch

    • Function name: owncloud-dedup-function

    • Runtime: Python 3.9

    • Permissions: Attach a previous role owncloud-dedup-role with basic Lambda permissions.

  4. Click Create function

Once created, open the function editor and paste your upload logic.

This function handles:

  • File hash computation (SHA-256)

  • Duplicate check in DynamoDB

  • Upload to S3 (if new)

  • Append user reference to existing files

  • Return stored path (symlink-style)


Step 2: Create the Delete Lambda Function

  1. Go back to the Lambda console

  2. Click Create Function again

  3. Select:

    • Function name: deleteFileLambda

    • Runtime: Python 3.11

    • Use the same role deleteFileLambda-role-wpp128e3 with S3 + DynamoDB access

  4. Paste the delete logic:

This function:

  • Removes a user's reference from the Users list in DynamoDB

  • Deletes the file from S3 if it has no users remaining


(Optional) Step 3: Assign IAM Role Permissions (for verification purpose)

Ensure both Lambda functions have access to:

  • S3 (PutObject, DeleteObject)

  • DynamoDB (GetItem, PutItem, UpdateItem, DeleteItem)

  • KMS (if using SSE-KMS encryption)

IAM Inline Policy Example:


Optional: Enable CloudWatch Logging

To help with debugging, enable CloudWatch logs:

  • Go to Lambda → Monitor tab → Enable CloudWatch Logs

  • Add print() statements inside your Lambda code


Lambda Functions Ready!

These two serverless functions are now capable of:

  • Deduplicating files intelligently

  • Tracking user-level file ownership

  • Cleaning up storage as users unlink

Last updated