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:
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-functionRuntime:
Python 3.9Permissions: Attach a previous role
owncloud-dedup-rolewith 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:
deleteFileLambdaRuntime:
Python 3.11Use the same role
deleteFileLambda-role-wpp128e3with S3 + DynamoDB access
Paste the delete logic:
This function:
Removes a user's reference from the
Userslist in DynamoDBDeletes 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