Tarek Cheikh
Founder & AWS Cloud Architect
How I built a secure, scalable file sharing solution using AWS Lambda, API Gateway, and Cognito — with zero infrastructure to manage
Your team needs a secure way to share files with external partners. You could use a third-party service, but you need full control over your data. You could build a traditional server-based solution, but that means managing infrastructure, scaling issues, and security headaches.
What if you could build an enterprise-grade file sharing platform that scales automatically, costs pennies to run, and requires zero infrastructure management?
That's exactly what I built with SmallFileSharing — and today, I'm sharing the blueprint with you.
In my consulting work at Toc Consulting, I frequently encounter enterprises that need:
Traditional solutions either lack features, cost too much, or require significant operational overhead.
The solution? Go serverless.
Here's the beauty of serverless architecture — every component automatically scales.
AWS Cognito: Handles user authentication with zero code. It provides:
AWS Lambda: Executes our business logic without servers:
DynamoDB: Tracks file metadata with predictable performance:
S3: Stores the actual files with 99.999999999% durability:
SES: Sends sharing notifications reliably:
Yes, I chose to base64-encode files in the API payload. Why?
{
"file_data": "iVBORw0KGgoAAAANSUhEUgAAB0QAAANi...",
"remote_file_name": "document.pdf"
}
For larger files, I'd implement direct S3 uploads with presigned URLs — but for 90% of business documents, 10MB is plenty.
Every Lambda function validates the JWT token and checks ownership:
def is_user_authorized(user_id, event):
'''Check if the user is authorized to access the file'''
url_user_id = event['path'].split('/')[3]
file_id = event['path'].split('/')[5]
if url_user_id != user_id:
return False, None
is_owned_by_user, file_infos = is_file_owned_by_user(user_id, file_id)
if not is_owned_by_user:
return False, None
return True, file_infos
This ensures users can only access their own files — critical for multi-tenant scenarios.
When sharing files, the system generates presigned S3 URLs that expire after 1 hour:
s3_client = boto3.client('s3', conf_values['REGION'])
response = s3_client.generate_presigned_url(
'get_object',
Params={
'Bucket': bucket_name,
'Key': file_path
},
ExpiresIn=3600 # 1 hour
)
This provides security without complexity — no need for recipient accounts or passwords.
Here's how the file sharing flow works:
POST /v1/users/{user_id}/files
Payload:
{
"file_data": "base64_encoded_data",
"remote_file_name": "document.pdf"
}
Response:
{
"file_id": "70ffa2f2-b106-4cbc-86c6-d5bab6959dcd",
"status": "UPLOADED"
}
The Lambda function:
{user_id}/{filename}POST /v1/users/{user_id}/files/{file_id}/share
{
"share_with": ["partner@company.com"]
}
The magic happens here:
Files can be deleted programmatically:
DELETE /v1/users/{user_id}/files/{file_id}
This removes both the S3 object and DynamoDB record — keeping storage costs minimal.
Let's talk numbers. For a typical usage pattern (1000 files/month, 5MB average):
Traditional Server Approach:
Serverless Approach:
That's a 91% cost reduction — and it scales linearly with usage!
After deploying this in production environments, here are my key takeaways:
The complete source code is available on GitHub under the MIT license: TocConsulting/small-file-sharing
I'm actively working on:
Serverless isn't just about cost savings — it's about focusing on what matters: solving business problems instead of managing infrastructure.
This file sharing platform handles production workloads for multiple enterprises, costs almost nothing to run, and required zero infrastructure decisions beyond the initial architecture.
The future of enterprise applications is serverless. Are you ready to make the jump?
Found this helpful? Give the GitHub repository a star and share this article with your network!
This article is just the start. Get the full picture with our free whitepaper - 8 chapters covering IAM, S3, VPC, monitoring, agentic AI security, compliance, and a prioritized action plan with 50+ CLI commands.
A complete beginner-to-builder guide for AWS SAM with Python. Learn to create, test locally, deploy, debug, and manage serverless APIs step by step.
How I built CognitoApi, an open-source serverless authentication API on AWS Cognito that handles 50,000 users for free with MFA, token management, and complete user lifecycle support.
Stop sending your IAM policies, CloudTrail logs, and infrastructure code to third-party APIs. Run LLMs locally with Ollama on Apple Silicon — private, offline, fast. Complete setup guide with AWS security use cases.