'uploading images to S3 using SDK skipping cloudfront

Setup:

We are running a E-commerce website consists of Cloudfront-->ALB-->EC2. we are serving the images from S3 via cloudfront behaviour.

Issue:

Our admin URL is like example.com/admin. We are uploading product images via admin panel as a zip file that goes via cloudfront.Each zip file size around 100MB-150MB consists of around 100 images. While uploading the zip file we are facing 502 gateway error from cloudfront since it took more than 30sec, which is default time out value for cloudfront.

Expected solution:

  1. Is there a way we can skip the cloudfront for only uploading images?

  2. Is there any alternate way increasing timeout value for cloudfront??

Note: Any recommended solutions are highly appreciated



Solution 1:[1]

CloudFront is a CDN service to help you speed up your services by caching your static files in edge location. So it won't help you in uploading side

In my opinion, for the uploading images feature, you should use the AWS SDK to connect directly with S3.

Solution 2:[2]

If you want to upload files directly to s3 from the client, I can highly suggest using s3 presigned URLs.

You create an endpoint in your API to create the presigned URL for a certain object (myUpload.zip), pass it back to the client and use that URL to do the upload. It's safe, and you won't have to expose any credentials for uploading. Make sure to set the expiration time to a reasonable time (one hour).

More on presigned URLs's here https://aws.amazon.com/blogs/developer/generate-presigned-url-modular-aws-sdk-javascript/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 LRutten