Backend & DevOps2026-08-23 21 min read

AWS S3 Cloud Storage & CloudFront CDN Integration

Building fault-tolerant media storage: generating presigned URLs on backends, direct browser uploading, and edge-caching configurations.

ED
EropaDev Tech Team
Infrastructure Engineer
#AWS S3 #Cloud Storage #CDN #Media Storage

When web applications scale horizontally across multiple instances, local file storage is no longer viable. Files uploaded to one server are missing on another. Utilizing a distributed object store like AWS S3 with CloudFront CDN solves this media hosting bottleneck permanently.

Amazon S3 (Simple Storage Service) guarantees high durability and availability of assets. Instead of uploading files to Laravel first and then forwarding them to S3 (which wastes server memory and processor cycles), we implement direct-to-S3 uploads via Presigned URLs.

The Laravel backend creates a temporary cryptographic signature permitting client browsers to PUT raw files straight to the S3 bucket. This eliminates proxy traffic on backend servers, supporting large file uploads without timeouts.

Here is the Laravel code for generating a secure S3 Presigned URL:

use Illuminate\Support\Facades\Storage;

$client = Storage::disk("s3")->getClient();
$expiry = "+20 minutes";

$command = $client->getCommand("PutObject", [
"Bucket" => config("filesystems.disks.s3.bucket"),
"Key" => "uploads/user_avatar_42.jpg",
"ContentType" => "image/jpeg"
]);

$request = $client->createPresignedRequest($command, $expiry);
$presignedUrl = (string) $request->getUri();

To distribute uploads with minimal latency, we link Amazon CloudFront as a CDN in front of the S3 bucket. CloudFront caches static assets at hundreds of edge locations globally. When users fetch an image, CloudFront serves it from the closest geographical node, minimizing network travel time.

It is critical to close public read access on the S3 bucket itself, restricting reads to CloudFront using an OAI (Origin Access Identity) policy. This blocks unauthorized bucket requests bypassing the CDN domain controls.

For e-commerce stores, we also implement real-time media compression using AWS Lambda@Edge. When an image is fetched through CloudFront for the first time, Lambda@Edge resizes it and compiles a WebP variant on the fly, saving up to 70% of image weight.

Deploying AWS S3 with CloudFront CDN ensures fast and secure content delivery to users worldwide while offloading servers and optimizing bandwidth costs.

Published by EropaDev Engineering Team