{"id":4211,"date":"2023-11-04T23:14:08","date_gmt":"2023-11-04T23:14:08","guid":{"rendered":"http:\/\/localhost:10003\/setting-up-cloudfront-distribution-for-your-web-application\/"},"modified":"2023-11-05T05:47:57","modified_gmt":"2023-11-05T05:47:57","slug":"setting-up-cloudfront-distribution-for-your-web-application","status":"publish","type":"post","link":"http:\/\/localhost:10003\/setting-up-cloudfront-distribution-for-your-web-application\/","title":{"rendered":"Setting up CloudFront Distribution for your web application"},"content":{"rendered":"
If you are running a web application, then ensuring it performs optimally across the world is essential. This is where AWS CloudFront comes in. CloudFront is a content delivery network that speeds up the distribution of your static and dynamic web content, such as HTML, CSS, JavaScript, and images, to your global audience. This tutorial will guide you through setting up a CloudFront distribution for your web application.<\/p>\n
Before starting this tutorial, you need the following:<\/p>\n
To get started, you need to decide where you want to host your web application. You can either host it on an S3 bucket or an EC2 instance. For S3, create an S3 bucket and upload your web application files to it. For EC2, launch an instance and set up a web server to host your web application.<\/p>\n
To set up CloudFront, you need to specify the origin from where CloudFront should fetch your web application files. This can be either an S3 bucket or an HTTP server hosted on EC2.<\/p>\n
If you are using an S3 bucket as your origin, you need to grant CloudFront access to the bucket. To do this, navigate to your S3 bucket and select the “Permissions” tab. Click on “Edit bucket policy” and paste the following policy:<\/p>\n
{\n \"Version\": \"2012-10-17\",\n \"Id\": \"PolicyForCloudFrontPrivateContent\",\n \"Statement\": [\n {\n \"Sid\": \"1\",\n \"Effect\": \"Allow\",\n \"Principal\": {\n \"AWS\": \"arn:aws:iam::cloudfront:user\/CloudFront Origin Access Identity YOUR-CLOUDFRONT-ACCESS-IDENTITY\"\n },\n \"Action\": \"s3:GetObject\",\n \"Resource\": \"arn:aws:s3:::YOUR-BUCKET-NAME\/*\"\n }\n ]\n}\n<\/code><\/pre>\nReplace “YOUR-CLOUDFRONT-ACCESS-IDENTITY” with the actual CloudFront access identity and “YOUR-BUCKET-NAME” with the actual S3 bucket name.<\/p>\n
If you are using an EC2 instance as your origin, you need to ensure that HTTP traffic is allowed on the instance. You can do this by adding a security group rule that allows incoming traffic on port 80 (HTTP).<\/p>\n
\n- Create a CloudFront distribution<\/strong><\/li>\n<\/ol>\n
To create a CloudFront distribution, navigate to the CloudFront console and click “Create Distribution.”<\/p>\n
In the “Web” section, click “Get Started.”<\/p>\n
Under “Origin Domain Name,” specify the domain name of your S3 bucket or EC2 instance. CloudFront will automatically detect the correct protocol (HTTP or HTTPS).<\/p>\n
Under “Viewer Protocol Policy,” select “Redirect HTTP to HTTPS.” This ensures that all traffic to your CloudFront distribution is encrypted.<\/p>\n
Under “Cache Key and Origin Requests,” select “Use legacy cache settings.” This is suitable for most web applications and provides better caching performance.<\/p>\n
Under “Distribution Settings,” specify a “Price Class” that determines the network coverage of your CloudFront distribution. Choose “Use All Edge Locations (Best Performance)” for global coverage or “Use Only US, Canada and Europe (Lowest Price)” for cost savings.<\/p>\n
Under “Alternate Domain Names (CNAMEs),” specify the domain name of your web application. This allows you to use a custom domain name instead of the default CloudFront domain name.<\/p>\n
\n- Configure SSL certificate<\/strong><\/li>\n<\/ol>\n
If you want to use a custom domain name with SSL, you need to configure an SSL certificate. You can either use a free SSL certificate provided by AWS Certificate Manager (ACM) or upload your own SSL certificate.<\/p>\n
To use an ACM certificate, navigate to the ACM console and click “Request a certificate.” Follow the prompts to generate a new SSL certificate for your custom domain name. Once the SSL certificate is issued, select your CloudFront distribution in the CloudFront console and click “Edit.” Under “SSL Certificate,” select “Custom SSL Certificate (example.com)” and select the ACM certificate from the dropdown menu.<\/p>\n
If you want to upload your own SSL certificate, you need to ensure that it is in PEM format and that it contains the private key. Once you have the SSL certificate in the correct format, select your CloudFront distribution in the CloudFront console and click “Edit.” Under “SSL Certificate,” select “Custom SSL Certificate (example.com)” and upload your SSL certificate.<\/p>\n
\n- Configure DNS<\/strong><\/li>\n<\/ol>\n
To use your custom domain name with CloudFront, you need to configure your DNS settings to point to your CloudFront distribution. You can either use Route 53, AWS’s DNS service, or your own DNS provider.<\/p>\n
If you are using Route 53, navigate to the Route 53 console and create a new Alias record set that points to your CloudFront distribution.<\/p>\n
If you are using your own DNS provider, you need to create a CNAME record that points to your CloudFront distribution.<\/p>\n
\n- Test your CloudFront distribution<\/strong><\/li>\n<\/ol>\n
Once you have configured your CloudFront distribution, you can test it by visiting your web application using your custom domain name.<\/p>\n
CloudFront provides detailed logs that can be used to troubleshoot any issues. To access the logs, navigate to your S3 bucket and select the “Properties” tab. Click on “Enable logging” and specify a Target Bucket, Prefix, and permissions. CloudFront logs will be written to the specified S3 bucket.<\/p>\n
Conclusion<\/h2>\n
In this tutorial, you learned how to set up a CloudFront distribution for your web application. CloudFront provides several benefits such as improved website performance, reduced latency, and better scalability. By following these steps, you can easily set up CloudFront for your web application and enjoy the benefits of AWS’s content delivery network.<\/p>\n","protected":false},"excerpt":{"rendered":"
Introduction If you are running a web application, then ensuring it performs optimally across the world is essential. This is where AWS CloudFront comes in. CloudFront is a content delivery network that speeds up the distribution of your static and dynamic web content, such as HTML, CSS, JavaScript, and images, Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[317,202,1711,1712,713,1710],"yoast_head":"\nSetting up CloudFront Distribution for your web application - Pantherax Blogs<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n