AWS: Lambda@Edge Now Available

Amazon Web Services (AWS) has made Lambda available at the Edge. By edge they mean the edge nodes of their CloudFront (CF) content distribution network (CDN). This mash-up of the two services allows for processing of final data all the way out to the point where it is almost reaching the client and allows for processing requests and the information passing through from the origin to the client / browser that made the request, but I am getting ahead of myself. For those of you who are not aware of what AWS, CF, or Lambda is, let’s start with what they are…

Amazon Web Services (AWS)

AWS is Amazon’s hardware and software cloud service. It sells access to hardware as well as partial and complete web service software and APIs – access points for the services using standard protocols – that developers use to produce an end product: processed data, a whole new desktop/web/mobile app, all the way up to a full-stack business/enterprise solution. In a nutshell, AWS provided the tools and necessary starting point of services to build something even bigger – they are the nuts, bolts, nails, screws, hammer, screwdriver, drill, boards, shaped wood, cement mixture, rebar, etc. that allows for producing a house.

Amazon Web Services' Lambda service logo - an orange Greek lambda character.

Lambda

Lambda is a service offered by AWS. In programming, a “lambda” function is any function that has no name. It is an island sitting in the middle of nowhere churning out, well… anything: new boats, manufacturing iPhones, etc. – but there is no company name behind the production. Lambda is a service that allows you to create one, ten, or millions of these no-name functions that respond to input from events. The event is a request that can be triggered by any number of things… a set amount of time (like a cron job), an inbound or outbound request be it from a browser, app, server, or another service. AWS has many “events” throughout it’s applications that can trigger these unknown functions sitting their invisibly analyzing, monitoring, altering, and sometimes adding to requests.

CloudFront (CF)

CloudFront is AWS’s content distribution network (CDN). These are proxies – they sit in front of other servers or services and store the results (when required to) temporarily that are passed back to it in response to a request that is made. There are “nodes” or sets of servers within one or more datacenter(s) in different parts of the world so that when someone or something makes a request, it gets directed to the node that is geographically closest to the requester. That way the information, once cached (or temporarily stored) get transferred more quickly than it would requesting from a server on the other side of the world.

Now that you know what each of these terms mean, lets dig into what the news means… The most obvious question being:

What does it do?

Lambda@Edge combines the Lambda service with the CF service. It adds events that are triggered by requests to the CF that in-turn call the Lambda function(s) that are assigned to the given event. The events are – in order of opperation:

  1. viewer request — Triggered immediately after a client (such as an app or browser) makes a request through the configured CF distribution.
  2. origin request — Triggered just before CF node makes the request to the origin server it is configured as a proxy for.
  3. origin response — Triggered after the origin server has returned a response to the request. It is not triggered under these conditions:
    • The response is stored in and served from the CF cache (in this case, none of the following events are triggered)
    • The origin response status code is 400 or higher (including 500 error codes)
    • A response was generated by a Lambda function that was triggered by the {previous} origin request event.
  4. viewer response — Triggered just before the response is sent to the client. It is not triggered under these conditions:
    • The origin response status code is 400 or higher (including 500 error codes)
    • A response was generated by a Lambda function that was triggered by the viewer request event.
    • The CF distribution is redirecting the client from an unsecured HTTP to an encrypted HTTPS connection.

What can I do with it?

What can’t you do with it? The possibilities are endless. It can be used to add additional headers into the response –Energizer Bunny beating on it's drum while floating through space. for instance, adding geography specific information based on client or distribution location; used to create and resell your own CDN services with advanced features such as content rewriting, content alteration, etc (like the “apps” of Cloudflare); call other cloud services (such as search engines, databases, big data storage tanks, etc.) and return completely custom content in near-real to real time; detect possible security issues within content and headers… like the Energizer Bunny the list goes on, and on, and on…

The pricing for both Lambda and CF have not changed so if you use both just sum up your usage (cost to use CF plus cost of using Lambda with CF equals total cost):

Lambda@Edge now Generally Available

Leave a Reply

Your email address will not be published. Required fields are marked *