I want AWS CloudFront to be implemented on production for a Magento 2 site.

i would like to know what changes are required to change the path of images and audio/ video files, to setup on S3 bucket.

Please note that the site will remain same, its just the media files will be moved to S3 bucket on AWS.

1 Answer 1


create two buckets for media and static, add CNAME aliases for your distributions ID:

CNAME media http://aaaaaaaaaa.cloudfront.net
CNAME static http://bbbbbbbbbb.cloudfront.net

so you will have:

ODN = http://magento-shop.com
OP = /pub/media
OID = http://media.magento-shop.com/pub/media

now change base media and static url:


add header to media in .htaccess or nginx:

Access-Control-Allow-Origin "*"

you can test with different paths and settings.

  • What url should i add in magento admin panel for media?
    – Nafsss
    Jul 11, 2019 at 4:53
  • What should be the folder name on S3 bucket. Do i need to follow the exact structure of folders inside media directory on S3 bucket also
    – Nafsss
    Jul 11, 2019 at 8:58
  • @MagenX.......i want to try this on local first, i will store my media and static folder on one server (11:111:111:111) and my magento on other server(10:100:100:000) now how can i put the url for my media and static, so that it should refer 11:111:111:111 and not 10:100:100:000
    – Nafsss
    Jul 11, 2019 at 11:46
  • Is there any documention for this. If yes then please share. I am still stuck into this
    – Nafsss
    Jul 17, 2019 at 11:10
  • I am able to fetch images from s3 bucket and see on my site. But when i try to add a new image to a product it could not get uploaded in s3. Why so? Do you have any idea about it .Please note, its only media files on S3 and not the static files. Do i need to add static files also on s3?
    – Nafsss
    Jul 30, 2019 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.