LoginSignup
2
4

More than 3 years have passed since last update.

CloudFrontの設定を他からコピーして設定する

Last updated at Posted at 2018-06-08

予めやっておいた方が良いこと

プロファイルの作成

aws --profile=プロファイル名 で切り替えられるように、~/.aws/{config,credentials}の設定を
aws configureで行っておく

SSL証明書の作成

AWS Certificate Manager CloudFrontのSLL証明書は、全世界で利用できるようにするためバージニア北部で作成しておく。
証明書に含めるドメインは2種類含めると良い( hoge.com と *.hoge.com のような2種類 )

この証明書のARN は

aws acm list-certificates --profile プロファイル名 --region us-east-1

で取得できる。

「--region us-east-1 」がポイント。CloudFrontで使用するSSL証明書は、バージニア北部(us-east-1)のものを指定する必要がある

既存の設定を取得する

AWSのCloudFrontの管理画面 で「ディストリビューション(CloudFrontの設定単位)のID」を確認する。

IDごとにある設定をjsonで取得する。

aws cloudfront get-distribution-config --profile=コピー元のAWSプロファイル --id [ CloudFrontの Distribution ID ] > ~/tmp/cloudfront_a.json

取得したjsonで書き換える箇所

消す

  • ETag ( aws-cli のヘルプ、 aws cloudfront get-distribution-config help で見ると、 The current version of the configuration. との事 )
  • DistributionConfig.CacheBehaviors は Behaviors を追加しない場合は削除

変更する

DistributionConfig配下の

設定 説明
各要素のQuantity 複数あるような設定の場合での個数(前の設定から消したりした場合は減らす)
CallerReference ディストリビューション(CloudFrontの設定単位) ごとにユニークである必要がある
Aliases.Items [ Alternate Domain Names (CNAMEs) ]になるものを設定
Origins.Items.Id オリジンに与えられる個別のIDを設定する。オリジンを変える場合は修正する
Origins.Items.DomainName オリジンのドメインを入れる。 https:// はつけないように
DefaultCacheBehavior.TargetOriginId 振り分けルールに無い、デフォルトの場合のオリジンを設定する( Origins.Items.Id で設定したものを設定した )
ViewerCertificate.ACMCertificateArn AWS Certificate で管理しているSSL証明書のARN
ViewerCertificate.Certificate AWS Certificate で管理しているSSL証明書のARN

作る

cd ~/tmp/
aws cloudfront --profile CDNを作るAWSプロファイル create-distribution --cli-input-json file://./cloudfront_a.json

下記のようなエラーが出た時は、各要素の「Quantity」で指定している要素数が合っているのか確認する。
設定を増やしたり減らしたりして、配列の中身の個数が変化している場合は変える必要がある。

An error occurred (InconsistentQuantities) when calling the CreateDistribution operation: The specified quantity of Origins (3) does not match the actual quantity supplied (1).
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4