
CloudFront is an Amazon Web Services (AWS) Content Delivery Network (CDN) service. One option is to return objects (files) in an S3 Bucket. For example, let's say you have an index.html file in your S3 Bucket.
And let's update the index.html file in the Bucket to have the Read Access Control List (ACL) for All Users. Check out my article Amazon Web Services (AWS) - Update S3 Bucket Object Access Control List (ACL) using the AWS CLI for more details on this. I am doing this because https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/GettingStarted.SimpleDistribution.html#GettingStartedUploadContent says:
By default, your Amazon S3 bucket and all of the objects in it are private—only the AWS account that created the bucket has permission to read or write the objects in it. If you want to allow anyone to access the objects in your Amazon S3 bucket using CloudFront URLs, you must grant public read permissions to the objects. (This is one of the most common mistakes when working with CloudFront and Amazon S3. You must explicitly grant privileges to each object in an Amazon S3 bucket.)
Let's create a CloudFront Distribution that uses the S3 Bucket as the origin.
Or, the CloudFront Distribution could be created using the aws cloudfront create-distribution command.
aws cloudfront create-distribution --origin-domain-name my-bucket-abc123.s3.amazonaws.com --default-root-object index.html
By default, S3 Buckets are set to block all public access. While it is definitely preferred to keep the S3 Bucket configured to block all public access to and setup a CloudFront Distribution with a non-public S3 Bucket, this is just meant to be the absolute least complex intro to CloudFront Distributions, so let's update the S3 Bucket to not block public access.
You should now have a Distribution domain name (d25ajrhgrwb9yb.cloudfront.net in this example). It may take a while, perhaps about 5 minutes, for the Distribution to be ready. Once Last modified shows a date and time, the Distribution should be good to go.
And there should be a behavior that contains HTTP and HTTPS for your S3 Bucket.
And you should now be able to get index.html using the CloudFront Distribution URL. Nice. Not too difficult, eh?
Did you find this article helpful?
If so, consider buying me a coffee over at