Access object of Private S3 Bucket from CloudFront

Access object of Private S3 Bucket from CloudFront

Prerequisites:

  • AWS Free Tier Account

Step 1: Create S3 Bucket

  • Go to S3 and click on create bucket

  • Select Specific Region

  • Bucket Name should be unique

  • Object Ownership ACLs enabled

  • Block Public Access settings for this bucket keep selected tick as default

  • Other things as default

  • Create bucket.

Step 2: Upload an object inside bucket

  • In the Buckets list, choose the name of the bucket that you want to upload your object to.

  • On the Objects tab for your bucket, choose Upload.

  • Under Files and folders, choose Add files.

  • Choose a file to upload, and then choose Open.

  • Choose Upload.

Step 3: Create Cloudfront distribution

  • Open the CloudFront console

  • Choose Create distribution

  • Origin domain Choose the Amazon S3 bucket that you created.

  • Origin path-optional

  • Name: same as bucket name or you can customize it

  • Origin access: select Origin access control settings then click on Create new OAC

  • Name: Keep it as default or set a unique name click on Create

  • Other setting keep as default.

  • Web Application Firewall: enable security protections

  • Default root object: optional or file name

  • Choose create distribution

Step 4: update bucket policy

  • After getting successfully created new distribution message now its time to update bucket policy.

  • As per picture given above copy policy and paste it to your bucket policy and save the settings.

Step 5: Access your content through CloudFront

  • Look at detail section wait untill Distribution state Last modified changes from Deploying to a Date and time

  • Record the domain name that CloudFront assigns to your distribution. It looks similar to the following: d111111abcdef8.cloudfront.net

  • Combine the domain name for your CloudFront distribution with the main page for your content.

    • Your distribution domain name might look like this: d111111abcdef8.cloudfront.net.

    • The path to the main page of a website is typically /index.html.

Therefore, the URL to access your content through CloudFront might look like this:

https://d111111abcdef8.cloudfront.net/index.html

  • Sharing a screenshot of my test.

Try and test with above steps, In this way with the help of cloudfront we can access private bucket object.

Happy Learning!!!

Thanks,

Bhairavi