CloudFront の継続的デプロイ(Continuous Deployment)は、本番トラフィックの一部をステージング環境に流して、CDN 設定変更を安全にテストできる機能

出典: Use CloudFront continuous deployment to safely test CDN configuration changes

“With Amazon CloudFront continuous deployment you can safely deploy changes to your CDN configuration by testing first with a subset of production traffic.”

なぜ必要か

従来の方法では、CDN 設定変更をテストするにはシミュレートされたトラフィックを使うしかなかった。継続的デプロイを使えば、実際の本番トラフィックの一部でテストできるため、より現実的な検証が可能になる

出典: Use CloudFront continuous deployment to safely test CDN configuration changes

“You can use a staging distribution and a continuous deployment policy to send some traffic from real (production) viewers to the new CDN configuration and validate that it works as expected.”

仕組み

プライマリディストリビューション(本番)とステージングディストリビューション(テスト用)の2つを用意し、継続的デプロイポリシーでトラフィックの振り分けを制御する

出典: Learn how continuous deployment works

“Viewers send requests to the primary (production) distribution, and CloudFront routes some of those requests to the staging distribution based on the traffic configuration settings in the continuous deployment policy.”

                              継続的デプロイポリシー
                             ┌─────────────────────┐
                             │ トラフィック設定     │
                             │ ・Weight-based: 10% │
                             │ ・Header-based      │
                             └──────────┬──────────┘
                                        │
  ユーザー                              │
     │                                  │
     │  リクエスト                       ▼
     │ ─────────────────────> ┌─────────────────────┐
     │                        │  プライマリ          │
     │                        │  ディストリビューション│
     │                        │  (本番環境)          │
     │                        └──────────┬──────────┘
                                         │
                          ┌──────────────┴──────────────┐
                          │                             │
                          ▼ 90%                         ▼ 10%
                 ┌─────────────────┐          ┌─────────────────┐
                 │   プライマリ     │          │  ステージング    │
                 │   (既存設定)     │          │  (新設定テスト)  │
                 └─────────────────┘          └─────────────────┘

注意: Flat-rate pricing plan では使えない

Flat-rate pricing plan(Free / Pro / Business / Premium)では継続的デプロイは使えない。pay-as-you-go のディストリビューションが必要

出典: CloudFront flat-rate pricing plans - Unsupported features

“Continuous deployment and Staging distributions - Use pay-as-you-go pricing”

トラフィックルーティングの種類

出典: Learn how continuous deployment works

Weight-based(重み付けベース)

指定した割合のトラフィックをステージングに送る

“A weight-based configuration routes the specified percentage of viewer requests to the staging distribution.”

Header-based(ヘッダーベース)

特定のHTTPヘッダーを含むリクエストのみステージングに送る。ローカルテストや制御されたリクエストに有効

“A header-based configuration routes requests to the staging distribution when the viewer request contains a specific HTTP header”

関連用語

プライマリディストリビューション

本番トラフィックを処理している既存の CloudFront ディストリビューション

ステージングディストリビューション

プライマリのコピーとして作成され、新しい設定をテストするためのディストリビューション。ユーザーが直接アクセスすることはできず、継続的デプロイポリシーを通じてのみトラフィックを受け取る

出典: Learn how continuous deployment works

“Viewers cannot send requests directly to a staging distribution using a DNS name, IP address, or CNAME. Instead, viewers send requests to the primary (production) distribution, and CloudFront routes some of those requests to the staging distribution based on the traffic configuration settings”

継続的デプロイポリシー

プライマリとステージング間のトラフィック分配を制御するポリシー