AWS S3 Pre-Signed URL Upload Architecture

November 30, 2026

Architecture Overview

Mobile app တွေမှာ large file တွေကို upload လုပ်တဲ့အခါ API Gateway ရဲ့ 10MB limit က ပြဿနာဖြစ်တယ်။ Pre-signed URL သုံးခြင်းအားဖြင့် client က S3 ကို တိုက်ရိုက် upload လုပ်နိုင်ပြီး size limit မရှိတော့ပါ။

🏗️ Architecture Comparison

FeatureDirect Upload ❌Pre-Signed URL ✅
File Size Limit10MB (API Gateway)5TB (S3 limit)
Upload SpeedSlowFast (direct to S3)
API Gateway LoadHighLow (URL gen only)
CostHigherLower
SecurityAPI GW authTime-limited URL
## 📊 How It Works 1. Mobile Client က API Gateway ကို pre-signed URL တောင်းတယ် 2. API Gateway က Lambda function ကို trigger လုပ်တယ် 3. Lambda က S3 pre-signed URL ကို generate လုပ်တယ် (15 minutes valid) 4. Lambda က URL ကို API Gateway မှတဆင့် client ကို ပြန်ပို့တယ် 5. Client က pre-signed URL သုံးပြီး S3 ကို တိုက်ရိုက် upload လုပ်တယ် (no API Gateway involved) > 💡 💡 Key Benefit: API Gateway bypass လုပ်ပြီး file size limit မရှိတော့ဘူး! ## ✅ Implementation Checklist - [ ] S3 Bucket ဆောက်ပြီး CORS configuration လုပ်မယ် - [ ] Lambda function (generate-presigned-url) deploy လုပ်မယ် - [ ] Lambda IAM role မှာ s3:PutObject permission ပေးမယ် - [ ] API Gateway REST API ဆောက်ပြီး Lambda integrate လုပ်မယ် - [ ] Client demo (HTML) နဲ့ test လုပ်မယ် - [ ] Production မှာ authentication ထည့်မယ် (API Key / Cognito) ## 🔐 Security Best Practices > 🔒 🔒 Pre-Signed URL Security - URL expiry time ကို သင့်လျော်အောင် သတ်မှတ်ပါ (default: 15 minutes) - Pre-signed URL က PutObject action တစ်ခုတည်းကိုပဲ ခွင့်ပြုပါ (no read/delete) - Content-Type validation လုပ်ပါ (PDF, images only, etc.) - File size limit ထည့်ပါ (Lambda မှာ validate လုပ်ပြီး URL မပေးခင် check) > 🛡️ 🛡️ S3 Bucket Security - Block all public access (ဘယ် user မှ direct access မရအောင်) - Enable versioning (မှားပြီး overwrite ဖြစ်ရင် ပြန်ရနိုင်အောင်) - Enable encryption at rest (AES-256) - Set lifecycle policies (90 days နောက် archive လုပ်မယ်) - Enable S3 access logs (audit trail အတွက်) > 🔑 🔑 API Gateway Security - Add API Key authentication (development အတွက် လုံလောက်တယ်) - Production မှာ Cognito User Pool သုံးပါ (OAuth 2.0 / JWT) - Rate limiting ထည့်ပါ (abuse ကာကွယ်ဖို့) - CORS ကို specific domains တွေကိုပဲ ခွင့်ပြုပါ (production မှာ \* မသုံးပါနဲ့) ## 💻 Code Implementation Full implementation (Lambda function, Terraform IaC, client demo) ကို GitHub မှာ ကြည့်ပါ: > 📂 📂 Code Location: /Users/zawwaisoe/Desktop/Labs/aws-s3-presigned-upload ### Lambda Function (Node.js) ```javascript const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3'); const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');

const s3Client = new S3Client({ region: process.env.AWS_REGION });

exports.handler = async (event) => { const { fileName, fileType, fileSize } = JSON.parse(event.body);

// Generate unique file key const fileKey = uploads/${Date.now()}-${fileName};

// Create command const command = new PutObjectCommand({ Bucket: process.env.S3_BUCKET_NAME, Key: fileKey, ContentType: fileType, });

// Generate pre-signed URL (expires in 15 minutes) const signedUrl = await getSignedUrl(s3Client, command, { expiresIn: 900 });

return { statusCode: 200, headers: { 'Access-Control-Allow-Origin': '*' }, body: JSON.stringify({ uploadUrl: signedUrl, fileKey }), }; };

### Terraform Deployment
```bash
# Configure
cd terraform
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars - set unique bucket name

# Deploy
terraform init
terraform plan
terraform apply

# Get API Gateway URL
terraform output api_gateway_url

Client Usage (JavaScript)

// Step 1: Request pre-signed URL
const response = await fetch('YOUR_API_GATEWAY_URL', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    fileName: file.name,
    fileType: file.type,
    fileSize: file.size
  })
});

const { uploadUrl, fileKey } = await response.json();

// Step 2: Upload directly to S3
await fetch(uploadUrl, {
  method: 'PUT',
  headers: { 'Content-Type': file.type },
  body: file
});

console.log('Upload success!', fileKey);

📚 📚 Resources

ObjectiveUnitRangeScale
Cost\$/hour0.1 - 5.0\~5
Latencymilliseconds1 - 100\~100
PerformanceGeekbench score1,000 - 40,000\~39,000