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
| Feature | Direct Upload ❌ | Pre-Signed URL ✅ |
| File Size Limit | 10MB (API Gateway) | 5TB (S3 limit) |
| Upload Speed | Slow | Fast (direct to S3) |
| API Gateway Load | High | Low (URL gen only) |
| Cost | Higher | Lower |
| Security | API GW auth | Time-limited URL |
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
- AWS S3 Pre-Signed URLs: https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html
- API Gateway Limits: https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
| Objective | Unit | Range | Scale |
| Cost | \$/hour | 0.1 - 5.0 | \~5 |
| Latency | milliseconds | 1 - 100 | \~100 |
| Performance | Geekbench score | 1,000 - 40,000 | \~39,000 |