Serving Images with CloudFront + S3
Table of Contents
- 1. Create an S3 Bucket
- 2. Create CloudFront Distributions
- 3. Check the Bucket Policy of S3
- 4. Operation Check
- 5. For More Information
Are you looking to efficiently serve images using AWS CloudFront and S3? This guide will walk you through the steps to set up this powerful combination for optimized image delivery.
1. Create an S3 Bucket
First, navigate to "Services > S3" in your AWS console. Then, create an S3 bucket with the following recommended settings:
Make sure to block all public access to the bucket, as shown in the image above.
2. Create CloudFront Distributions
Now, go to "Services > CloudFront" and create a distribution. Here's what you need to configure:
- Origin Domain Name: Select the S3 bucket you created in step 1.
- Restrict Bucket Access: Set this to "Yes" to restrict access to S3 only from CloudFront.
- Origin Access Identity: If you're creating your first CloudFront Distribution, choose "Create a New Identity." If you've already created an "origin access identity," you can select it from "Use an Existing Identity." Typically, one "origin access identity" is sufficient.
- Grant Read Permissions on Bucket: Set this to "Yes" and choose "Update Bucket Policy." This will automatically add a policy setting to S3's Bucket Policy. Refer to step 3 for more details.
All other values can remain as their default, which are typically the recommended settings.
As shown in the screenshots above, the S3 images are served with the URL of the "Domain Name."
3. Check the Bucket Policy of S3
To ensure everything is set up correctly, go to "Services > S3 > [Your bucket] > Permissions > Bucket Policy."
You'll see that a policy, as depicted in the image above, is automatically set.
4. Operation Check
Now, for a quick operation check, upload an image to your S3 bucket for testing. Use the default and recommended values.
First, open the S3 "Object URL" and verify that it returns an "Access Denied" message.
Next, open CloudFront's "Domain Name," and you should see the image displayed correctly.
5. For More Information
For more in-depth information and details, you can refer to the official AWS CloudFront documentation.
This setup allows you to efficiently serve images using the power of CloudFront and S3 while ensuring secure access control. Enjoy your optimized image delivery! 🚀
Comments (0)
What are your thoughts on "Serving Images with CloudFront + S3"?
You need to create an account to comment on this post.