AWS S3 with CloudFront, high-performance security
Updated: Jul 16
Services
Amazon CloudFront is a content delivery network (CDN) service built for high-performance security, and developer convenience can be used as the frontend of many services (S3 Buckets, ELB’s, media distribution, and any other HTTP server running in ec2 instance or any other kind of host).
![""](https://static.wixstatic.com/media/eabb33_427cca9cfd864a919502c35c31f52bef~mv2.png/v1/fill/w_520,h_320,al_c,q_85,enc_auto/eabb33_427cca9cfd864a919502c35c31f52bef~mv2.png)
Besides, Cloudfront uses edge locations to cache copies of the content that it serves, so the content is closer to users and can be delivered to them faster. Edge locations are AWS data centers designed to deliver services with the lowest latency possible. Amazon has dozens of these data centers spread across the world. They’re closer to users than Regions or Availability Zones, often in major cities, so responses can be fast and snappy.
Then, we will use Cloudfront to deliver access from Edge Locations to S3 Buckets, which can be used for static websites or, in this case, as file server storage.
Resources
First, we begin creating a Terraform infrastructure, which contains the next resources:
AWS CloudFront Distribution as Frontend access
AWS S3 Bucket for Storage
AWS Route 53 Zone for records
SSL Certificate
IAM user/group: Credentials for users
IAM Policies: Access and manage of Buckets
After applying this plan we can view the below resources in AWS Console:
Cloudfront Distribution
![""](https://static.wixstatic.com/media/eabb33_3431402c7c7c4b71b0d908c1cdda2460~mv2.png/v1/fill/w_684,h_164,al_c,q_85,enc_auto/eabb33_3431402c7c7c4b71b0d908c1cdda2460~mv2.png)
AWS S3 Bucket
![""](https://static.wixstatic.com/media/eabb33_22011c9311a54349b15f2d636a6ce395~mv2.png/v1/fill/w_692,h_165,al_c,q_85,enc_auto/eabb33_22011c9311a54349b15f2d636a6ce395~mv2.png)
![""](https://static.wixstatic.com/media/eabb33_9864984a8a89405d98aa0aaab41fc734~mv2.png/v1/fill/w_673,h_364,al_c,q_85,enc_auto/eabb33_9864984a8a89405d98aa0aaab41fc734~mv2.png)
Note: Remember to set Bucket as private and manage the access through Cloudfront.
![""](https://static.wixstatic.com/media/eabb33_89f5dfc0c55748f0a8c214abe45973d8~mv2.png/v1/fill/w_356,h_215,al_c,q_85,enc_auto/eabb33_89f5dfc0c55748f0a8c214abe45973d8~mv2.png)
Cloudfront OAI
We need to configure OAI because we want Cloudfront to access S3 private buckets.
![""](https://static.wixstatic.com/media/eabb33_1aa3cf0e7d424756b53cce1200936807~mv2.png/v1/fill/w_624,h_466,al_c,q_85,enc_auto/eabb33_1aa3cf0e7d424756b53cce1200936807~mv2.png)
And finally, is necessary to attach OAI Policies to CDN (S3 Origin config).
![""](https://static.wixstatic.com/media/eabb33_995854da44844b0a85ae7d3f36ac48bc~mv2.png/v1/fill/w_668,h_100,al_c,q_85,enc_auto/eabb33_995854da44844b0a85ae7d3f36ac48bc~mv2.png)
Route 53
In this case, we suppose that Route53 is already created, so we will use Data Sources from Terraform to retrieve the resource.
SSL Certificate
After, if you don’t have a certificate ssl for this record domain or a wildcard ssl for a whole domain, you can create and deploy a free certificate in ACM:
IAM
We need to create a group with policies to allow access and list buckets, then add users to this group.
![""](https://static.wixstatic.com/media/eabb33_d3bbde4bde674f548c557d57132796bd~mv2.png/v1/fill/w_667,h_331,al_c,q_85,enc_auto/eabb33_d3bbde4bde674f548c557d57132796bd~mv2.png)
![""](https://static.wixstatic.com/media/eabb33_705bc7254c9448eea6cf3df17e3dd04c~mv2.png/v1/fill/w_644,h_278,al_c,q_85,enc_auto/eabb33_705bc7254c9448eea6cf3df17e3dd04c~mv2.png)
Policies:
![""](https://static.wixstatic.com/media/eabb33_4955b699e7db4da8be6bba5aaad6d04b~mv2.png/v1/fill/w_519,h_423,al_c,q_85,enc_auto/eabb33_4955b699e7db4da8be6bba5aaad6d04b~mv2.png)
Desktop GUI - S3 Access
Well, we have a Cloudfront Distribution which is used for access to S3 Resources and upload/download files, but we don’t want users to login into our AWS Platform and navigate through to S3, doesn't seem to be a good practice.
Then, we will use the Cyberduck client, a desktop platform that connects to any Amazon S3 Storage region with support for large file uploads.
If you have in AWS US you need to select the next profile:
![""](https://static.wixstatic.com/media/eabb33_e2138c6edaa84744b1accfda017a0503~mv2.png/v1/fill/w_622,h_47,al_c,q_85,enc_auto/eabb33_e2138c6edaa84744b1accfda017a0503~mv2.png)
Note: If you use other AWS platforms (like GOV or China) you can download the right profile from the Cyberduck official webpage.
Finally, we can connect with the user access keys, navigate and open our buckets, and upload or download files within.
References
Cloudfront + S3 example: https://github.com/teracloud-io/cfs3-blog
Terraform resources: https://registry.terraform.io/providers/hashicorp/aws/latest/docs
Cyberduck Client: https://cyberduck.io/
If you are interested in learning more about our TeraTips or our blog's content, we invite you to see all the content entries that we have created for you and your needs.
Comments