How a request actually flows
Six hops, three Lambda functions, zero servers to patch. The client never sends file bytes through the backend — it only ever asks for permission, then talks to S3 on its own.
- Users upload files through a web interface.
- A Lambda function generates a presigned S3 URL and returns it.
- The file uploads directly to S3 using that presigned URL.
- S3 emits an ObjectCreated event notification.
- The SaveMetadata Lambda reads the object's metadata and stores it in DynamoDB.
- The client calls GET /files to read back everything that's been uploaded.
Create the S3 bucket
The bucket is the landing zone for every uploaded file. Objects are namespaced under a single prefix so the bucket stays organized as it grows.
Folder structure
s3:GetObject statement; write access is granted only through presigned URLs, never opened publicly.Create the DynamoDB table
One table stores a record per uploaded file, keyed by a generated ID rather than the filename — so two people can upload report.pdf without colliding.
Create the IAM execution role
Every Lambda in this pipeline runs under a role scoped to exactly what it touches: object storage, the metadata table, and its own logs.
| Policy | Grants |
|---|---|
| AmazonS3FullAccess | Read / write objects in the upload bucket |
| AmazonDynamoDBFullAccess | Read / write items in meofiles |
| CloudWatchLogsFullAccess | Ship function logs for debugging |
Lambda: GenerateUploadURL
This function never sees the file itself — it just signs a temporary PUT URL that lets the client write one specific object, for a limited window of time.
import json import boto3 from botocore.client import Config s3 = boto3.client("s3", config=Config(signature_version="s3v4")) BUCKET = "meo-bucket-26" def lambda_handler(event, context): filename = event["queryStringParameters"]["filename"] key = f"upload-files/{filename}" upload_url = s3.generate_presigned_url( ClientMethod="put_object", Params={"Bucket": BUCKET, "Key": key}, ExpiresIn=300, HttpMethod="PUT", ) return { "statusCode": 200, "headers": {"Access-Control-Allow-Origin": "*"}, "body": json.dumps({"uploadURL": upload_url, "key": key}), }
Wire up API Gateway
A REST API with a single /upload resource, backed by Lambda proxy integration so the function receives the full request untouched.
| Setting | Value |
|---|---|
| Endpoint type | Regional |
| Resource path | /upload |
| Method | GET, Lambda proxy integration |
| Integration target | GenerateUploadURL |
Enable CORS
If the frontend is served from S3 or CloudFront, the browser will block the request without explicit CORS headers on both API Gateway and the bucket.
| Setting | Value |
|---|---|
| Allowed origin | http://meo-bucket-26.s3-website-us-east-1.amazonaws.com |
| Allowed methods | GET, PUT, HEAD, OPTIONS |
| Allowed headers | Content-Type, Authorization |
Then deploy the API to a stage — creating it isn't enough, it has to be published before it's callable.
S3 event → SaveMetadata Lambda
The bucket's ObjectCreated event is wired to a second function, which reads the object's headers straight from S3 and persists them as a row in DynamoDB.
import json, boto3, uuid from urllib.parse import unquote_plus from datetime import datetime s3 = boto3.client('s3') table = boto3.resource('dynamodb').Table('meofiles') def lambda_handler(event, context): for record in event['Records']: bucket = record['s3']['bucket']['name'] key = unquote_plus(record['s3']['object']['key']) head = s3.head_object(Bucket=bucket, Key=key) table.put_item(Item={ "FieldID": str(uuid.uuid4()), "FileName": key.split("/")[-1], "Bucket": bucket, "ObjectKey": key, "FileSize": head["ContentLength"], "ContentType": head["ContentType"], "UploadDate": datetime.utcnow().isoformat(), "Status": "Uploaded", }) return {"statusCode": 200, "body": "Metadata Saved"}
Lambda: GetFiles
A read-only endpoint that scans the table and hands the frontend everything it needs to render an upload history — no separate database layer required.
import json, boto3 from decimal import Decimal table = boto3.resource('dynamodb').Table('meofiles') class DecimalEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, Decimal): return int(obj) return super().default(obj) def lambda_handler(event, context): response = table.scan() return { "statusCode": 200, "headers": {"Access-Control-Allow-Origin": "*"}, "body": json.dumps(response["Items"], cls=DecimalEncoder), }
Exposed as GET /files on the same API Gateway, so the whole pipeline lives behind two clean endpoints: one to write, one to read.
Verify the pipeline end-to-end
With every piece wired up, the last step is confirming the full round trip from a real browser — upload, storage, and metadata — rather than trusting each Lambda in isolation.
1 · Upload through the web interface
A minimal frontend calls GET /upload?filename=…, receives the presigned URL, then PUTs the file straight to S3.