Deploying a Full-Stack E-Commerce App on AWS with S3 and CloudFront
Deploying a full-stack application to AWS can feel daunting, but with the right approach it's a smooth process. In this post I'll share exactly how I migrated the Jhumkeshwari e-commerce platform to AWS.
Architecture
Setting Up S3 for Image Storage
I replaced local `multer` disk storage with `multer-s3` to stream uploads directly to S3. This eliminated the need to store images on the EC2 instance and made the app stateless.
const multerS3 = require('multer-s3');
const s3 = new AWS.S3();
const upload = multer({
storage: multerS3({
s3: s3,
bucket: process.env.S3_BUCKET_NAME,
key: (req, file, cb) => {
cb(null, `products/${Date.now()}-${file.originalname}`);
}
})
});
CloudFront for CDN
With CloudFront in front of S3, image delivery is fast globally. I updated all image URLs to use the CloudFront distribution URL instead of direct S3 URLs.