Build guide · AWS

A file lands in S3.
Its metadata lands in DynamoDB.
No server ever runs.

A complete, presigned-URL upload pipeline built entirely from managed AWS services — API Gateway, Lambda, S3 and DynamoDB — wired together so the client talks to storage directly and the backend only ever handles metadata.

Amazon S3 API Gateway AWS Lambda · Python 3.13 DynamoDB IAM CloudWatch
// architecture

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.

  1. Users upload files through a web interface.
  2. A Lambda function generates a presigned S3 URL and returns it.
  3. The file uploads directly to S3 using that presigned URL.
  4. S3 emits an ObjectCreated event notification.
  5. The SaveMetadata Lambda reads the object's metadata and stores it in DynamoDB.
  6. The client calls GET /files to read back everything that's been uploaded.
presigned upload User API Gateway Lambda GenerateUploadURL Lambda GetFiles Amazon S3 bucket ObjectCreated event Lambda SaveMetadata DynamoDB · meofiles
// step 01

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

bucketmeo-bucket-26
prefixupload/
Bucket policy — objects are readable via a scoped s3:GetObject statement; write access is granted only through presigned URLs, never opened publicly.
// step 02

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.

table namemeofiles
partition keyFileID (String)
status● active
// step 03

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.

PolicyGrants
AmazonS3FullAccessRead / write objects in the upload bucket
AmazonDynamoDBFullAccessRead / write items in meofiles
CloudWatchLogsFullAccessShip function logs for debugging
// step 04

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.

generate_upload_url.py
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}),
    }
Why 300 seconds — short-lived URLs limit the blast radius if one ever leaks in a log or a browser history.
// step 05

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.

SettingValue
Endpoint typeRegional
Resource path/upload
MethodGET, Lambda proxy integration
Integration targetGenerateUploadURL
request/upload?filename=test.pdf
status200 OK · 60ms
response{ "uploadURL": "https://…", "key": "uploads/test.pdf" }
// step 06

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.

SettingValue
Allowed originhttp://meo-bucket-26.s3-website-us-east-1.amazonaws.com
Allowed methodsGET, PUT, HEAD, OPTIONS
Allowed headersContent-Type, Authorization

Then deploy the API to a stage — creating it isn't enough, it has to be published before it's callable.

// step 07

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.

save_metadata.py
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"}
No polling — S3 invokes this function directly the moment an object lands. The permission for S3 to call Lambda is added automatically when the event notification is saved.
// step 08

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.

get_files.py
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.

// step 09

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.

actionChoose file → Upload
requestPUT presigned S3 URL
result✓ File uploaded successfully

2 · Confirm the object landed in S3

bucketmeo-bucket-26
prefixupload-files/
object● present

3 · Confirm the metadata landed in DynamoDB

tablemeofiles
itemFieldID, FileName, Bucket, ObjectKey, FileSize, ContentType, UploadDate
statusUploaded
What this proves — the browser never touched the backend to move bytes, yet the metadata table stays in perfect sync with what's actually sitting in the bucket, driven entirely by the S3 event.