Lambda@Edge event structure
The following topics describe the request and response event objects that CloudFront passes to a Lambda@Edge function when it's triggered.
Dynamic origin selection
You can use the path pattern in a
cache behavior to route requests to an origin based on the path and name
of the requested object, such as images/*.jpg. Using Lambda@Edge, you
can also route requests to an origin based on other characteristics, such as the
values in request headers.
There are a number of ways that this dynamic origin selection can be useful. For example, you can distribute requests across origins in different geographic areas to help with global load balancing. Or you can selectively route requests to different origins that each serve a particular function: bot handling, SEO optimization, authentication, and so on. For code examples that demonstrate how to use this feature, see Content-based dynamic origin selection - examples.
In the CloudFront origin request event, the origin object in the event
structure contains information about the origin that the request would be routed to,
based on the path pattern. You can update the values in the origin
object to route a request to a different origin. When you update the
origin object, you don't need to define the origin in the
distribution. You can also replace an Amazon S3 origin object with a custom origin
object, and vice versa. You can only specify a single origin per request, though;
either a custom origin or an Amazon S3 origin, but not both.
Request events
The following topics show the structure of the object that CloudFront passes to a Lambda function for