Search code examples
amazon-web-servicesamazon-s3amazon-cloudfront

AWS S3 : Pricing for invalidation requests for React. js application hosted on S3


I have a web application developed using React.js, HTML and Java script. This react.js web application calls the backend REST APIs.

I have hosted this web application on AWS S3.

I am able to access the web application using HTTP.

To enable HTTPs based access, I am planning to use AWS cloud front.

I don't have much static media content, but few css, js and few small images.

As I understand the pricing for Cloud front is based on

  1. Amount of Data transfer
  2. No. of HTTP/HTTPS Requests
  3. Invalidation Requests

In my case, the web application makes HTTPs calls to the backend when the user requests for a web page or wants to search the records.

I want to know if this every request to the backend is treated as "Invalidation Request" ?

Or does the invalidation requests is applicable only when the static content (HTML, CSS, JS, images) are changed?

Is there any other cost effective option for enabling HTTPs for S3 based web applications?


Solution

  • You would only create an invalidation request if you wanted to purge the CloudFront cache of cached content (ie old version of files) and use a new version.

    With your React / HTML / CSS project, you'll put it in the S3 bucket, and set your S3 bucket as the Origin for CloudFront. When CloudFront fetches the objects from S3, it will cache them in its edge cache for future requests for the TTL (time-to-live) of the object. The object will remain there, and CloudFront will not check your origin for a new version of the object until the TTL has expired.

    An invalidation request will tell CloudFront to purge the objects from the cache and since they are no longer in the cache, when a request comes to CloudFront it will get the object from your S3 bucket.

    Basically, every time you publish a new production build, you'll need CloudFront to be using new versions of your objects, so you'll want to do an invalidation every time you put a new version of you object in to production.

    You can read more about invalidations and the costs of invalidations here: https://aws.amazon.com/blogs/aws/simplified-multiple-object-invalidation-for-amazon-cloudfront/

    It's worth noting that we do 5-10 releases per day, and our CodePipeline takes care of the invalidations for us. We've never paid any charges for invalidations. Also, just a heads up that, in my experience, depending on the number of objects being invalidated, invalidations can take anywhere from just a few minutes, to over 30 minutes.