Introduction to Amazon CloudFront
Click on Close and you can see an object in the bucket. 3. Creating Custom Error Pages Ensure that the error pages are stored in a location that CloudFront can access. We will use the same S3 bucket that we created previously. Set up a custom error page. Click S3 bucket. Click on Create Folder button and create a folder with the name CustomErrors For Server-side encryption Select Specify an encryption key keep rest things as default. Click on the Create folder button. Click on the new CustomErrors folder. We will create an error.html file: Create an error.html file in your local system using Notepad. This custom HTML page will be used for showing errors in CloudFront. Use the Upload button to upload the error.html file in the folder. We will create a block.html file: Create a block.html file in your local using Notepad. This custom HTML page will be used for showing geo-restrictions of your content in CloudFront. Use the Upload button to upload the block.html file in the folder. 4. Making the objects public Click on the image name. Copy the Object URL and paste it into a new tab. You will see the AccessDenied message, meaning the object is not publicly accessible. Go back to the Bucket and click the Permissions tab. Scroll down to the Bucket Policy and click on Edit button. Copy and paste the policy and save the policy. Open the Image Object URL again or refresh the one already open. If you can see your uploaded image in the browser, it means your image is publicly accessible. If not, check your bucket policy again. 5. Creating a CloudFront Distribution Click on CloudFront in the Network and Content Delivery section. Click on Create a CloudFront distribution button. Configure distribution. Origin Domain Name: On click of input space, Select your S3 bucket. Choose Do not enable (WAF). Leave everything default, scroll down, and click on the Create distribution button. You can see that the CloudFront distribution is enabled successfully. The domain name that Amazon CloudFront assigns to your distribution appears in the list of distributions. 6. Accessing Image through CloudFront Amazon CloudFront is now pointed to Amazon S3 bucket origin and the domain name is associated with the distribution. Create a link to the image in the Amazon S3 bucket with that domain name. For testing your distribution, copy your domain name and append your image name after the domain name. Open the CloudFront URL in a new tab. You can see your uploaded image. You can see how much faster the CloudFront URL image loads as compared to the S3 URL. When end users request an object using a CloudFront domain name, they are automatically routed to the nearest edge location for high-performance delivery of your content. 7. Configuring Custom Error Page Go back to CloudFront Dashboard and select the distribution created. Select the Error pages tab. Click on the Create custom error response button. Set up our custom error page: HTTP Error Code: Select 404: Not Found Error Caching Minimum TTL: Enter 10 Customize Error Response: Select Yes Response Page Path: Enter /CustomErrors/error.html HTTP Response Code: Select 404: Not Found Click on Create custom error response button. Navigate back to Distributions and wait for your distribution to complete state to change Deploy. Enter the URL of an image that does not exist in your S3 bucket with the CloudFront domain name. You can see your HTML error page in the browser, means you successfully set up your custom error page. 8. Restricting the Geographic Distribution of Your Content On the distribution settings page, select Security tab and expand CloudFront geographic restrictions click on Edit link near Countries. select Restriction Type: Select Block list Select the country where you are currently and click on it to check this option. Click on Save changes button. Go to the distribution list and wait for your distribution to complete the state changed to deployed. Once the state has been changed to deployed, we will test the restriction through CloudFront in the browser. You can see the error message: Let us configure a custom error page: Go back to CloudFront Dashboard and select the distribution you have created. On the settings page, select Error pages tab. Click on the Create custom error response button. select Http Error Code: Select 403: Forbidden Error Caching Minimum TTL: Enter 10 Customize Error Response: Select Yes Response Page Path: Enter /CustomErrors/block.html HTTP Response Code: Select 403: Forbidden Click on Create custom error response button. Go back to Distributions and wait for your distribution to complete state to change Deploy. Once the state has been changed to Deploy, we will test the restriction through CloudFront in the browser. If you see the error, this means you successfully configured a custom error page and restricted image access from your country.
Download
0 formatsNo download links available.