This week I will give some examples about Cloudfront error pages, restrictions and invalidation. We can customize our responses if our origin server have some issue. For example , the requested object can’t be found or we can get an access denied error. In this case, we can use Cloudfront error pages configuration. If we want to apply geo restriction, we can use restriction configuration for our distribution. We can select white or blacklist restriction as restriction type. And finally, if we change an object and want it to be served immediately, we have to invalidate it. I will also show the invalidation configurations.
I will start with error pages. I uploaded two objects to my S3 bucket.
When I browse “AWS-Solutions-Architect-Associate.png”, Cloudfront will serve it as seen below.
Before I configured custom error response, if I request a non-exist object, I got an error page like this.
Now I configure an custom error response as below. I want all Forbidden requests to be served as 200 and show them “gandalf.jpg” to the requester.
After the new configuration is deployed, I request the same object and now Cloudfront will server “gandalf.jpg” wth HTTP status code 200.
Now let’s talk about geo-restriction. By default, geo-restriction is disabled. I will configure it and blacklist Turkey for our demo as shown below.
If I try to browse “http://d1i68eqchx933m.cloudfront.net/AWS-Solutions-Architect-Associate.png” from Turkey, I won’t be able to see it. And I will try to browse it from UK, and I will succeed.
Finally we can configure the invalidation. If we update an object and want to remove it before it expires, we have to invalidate it. We can also using versioning to achieve this. We can version the objects like gandalf_1.jpg, gandalf_2.jpg and update our code/links to serve the new object. Other way is using cloudformation invalidation (we can invalidate a specified number of objects each month for free ). Let’s see how it works.
I uploaded “before.jpg” and now I browse it.
I uploaded another file with the same name and now I will create and invalidation.
As you see it is in progress. As soon as invalidation finishes, I will be able to see the new version.
And the new version:
In my next post I am planning to start RDS. If you have any question or comment, please feel free to write and don’t forget to share please.