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:
Upload Handler — triggered when a user uploads a file
Delete Handler — triggered when a user deletes/unlinks a file
Step 1: Create the Upload Lambda Function
Go to AWS Console → Lambda
Click Create Function
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.
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
Go back to the Lambda console
Click Create Function again
Select:
Function name: deleteFileLambda
Runtime: Python 3.11
Use the same role deleteFileLambda-role-wpp128e3 with S3 + DynamoDB access
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)