AWS Lambda@Edge 讓 Lambda 支援用 CloudFront 做 Cache

2017-07-19 AWS

去年 AWS 才推出 Lambda@Edge Preview,今天 AWS 正式推出 Lambda@Edge「Lambda@Edge – Intelligent Processing of HTTP Requests at the Edge」也就是說你可以在離你最近的 Cloudfront 節點執行 Lambda function

 

在實作上其實就是用 Cloudfront 去接 Lambda

 

Developer Guide 有提到 Lambda@Edge 是基於 AWS Regions and Amazon CloudFront edge locations 的環境。

Lambda@Edge lets you run Lambda functions at AWS Regions and Amazon CloudFront edge locations in response to CloudFront events, without provisioning or managing servers. You can use Lambda functions to change CloudFront requests and responses at the following points:

 

Lambda@Edge 執行的示意圖:

你可以在 Lambda@Edge 執行的 solutions

  • Inspect cookies to rewrite URLs to different versions of a site for A/B testing.
  • Send different objects to your users based on the User-Agent header, which contains information about the device that submitted the request. For example, you can send images in different resolutions to users based on their devices.
  • Inspect headers or authorized tokens, inserting a corresponding header and allowing access control before forwarding a request to the origin.
  • Add, delete, and modify headers, and rewrite the URL path to direct users to different objects in the cache.
  • Generate new HTTP responses to do things like redirect unauthenticated users to login pages, or create and deliver static webpages right from the edge. For more information, see Using Lambda Functions to Generate HTTP Responses to Viewer and Origin Requests in the Amazon CloudFront Developer Guide.

 

就 Lambda@Edge 定價 來說不算貴

您需要根據您的所有函數請求總數支付費用。Lambda@Edge 每次在任何全域節點開始執行以回應 CloudFront 事件,就會視為一個請求。

請求定價為每 1 百萬個請求 0.60 USD (每個請求 0.0000006 USD)。

 

但 Lambda@Edge 沒有 free tier,所以會比 Lambda 本身再貴一點,不過 AWS 的 Serverless 越來越齊全了。

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

彙整

分類

open all | close all

License

訂閱 Mr. 沙先生 的文章

輸入你的 email 用於訂閱