I have an S3 bucket called my-bucket. There is a folder inside my-bucket called uploaded-photos.
I can access the photos inside this bucket using the following URL:
http://my-bucket.s3-ap-southeast-2.amazonaws.com/uploaded-photos/imag-1.jpg
I have defined the following CloudFront behavior, so that all the .jpg images in the bucket are served from CloudFront.
After adding the images to CloudFront, I can access them using website root, i.e:
www.my-website.com/uploaded-photos/imag-1.jpg
This is because I have the following CloudFront distribution:
I am not sure which one of these url I should use to server photos in my code? Does both of these URL get the photos from CloudFront edge location?
Use either of the two URLs in the green box.
You could create an Origin Access Identity to block direct S3 bucket access, forcing requests to go through CloudFront.