As shown in the previous log, my function only needed 36MB and 1 second to run.
So, I can call it more than 3 million times and still pay nothing at the end of the month.
After that I create a cache invalidation in my Cloudfront Distribution for that object. If the file is index.html, then the path to invalidate is "/". It makes no sense to invalidate an object that never existed before.
But since invalidation calls are so cheap (free for me because of the small number of request I make) I don't really care : D This Lambda function needs to be able to create the invalidation requests in Cloudfront, so a role that allows that task needs to be applied to it.
As soon as this is completed (preferably with a short DNS TTL) then the new Cloud Front distribution will be hit by clients and will be filled up with the new versions of the objects.
After a while, you would then destroy and stop paying for the original Cloud Front distribution that is no longer being referenced or used.
This will ensure that your CDN always serves the latest versions of your files.
After each deployment it will send a list of files to invalidate to your Cloud Front distribution.
With 128MB I can call this function 3.200.000 times per month for free.
After that, the cost will be 0.000000208$ for every 100ms of execution.
Those functions can be associated to a particular AWS service and when something happens they trigger and run the code. With Lambda Functions you could: And everything could be triggered by a simple "put" command in one of the configured S3 buckets. Actually, you could build your entire app with Amazon Lambda Functions without having to start a single server.
I have my entire site and blog hosted in Amazon S3, then distributed around the world with Amazon Cloudfront.
Here is the step by step: Well, easy, just need to login on your Amazon Console, choose the Availability Region and then open the AWS Service. I need to choose which Amazon service will trigger the function.