すらいむがあらわれた

こまんど >  たたかう  にげる

AWS SDK for .NETでCloudFront Distributionの作成(Custom Originの場合)

CloudFrontのOriginにはS3 Bucketだけでなく、公開しているサーバーを指定することが可能です。
これを「CustomOrigin」と呼びます。

AWS発表】 Amazon CloudFront(コンテンツ配信サービス)の配信元としてS3以外のユーザ指定サーバ(オリジン)を使用可能 - Amazon Web Services ブログ
http://aws.typepad.com/aws_japan/2010/11/cloudfront-origin-server.html

Parts of a Distribution - Amazon CloudFrontDeveloper Guide
http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?AboutCreatingDistributions.html

                                                                                          • -

Custom Origin

A custom origin is any origin server that isn't hosted on Amazon S3. A custom origin might be located on a set of servers you manage privately, or it could be an Amazon EC2 instance.

                                                                                          • -

Creating a Distribution with a Custom Origin - Amazon CloudFrontDeveloper Guide
http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?CreatingDistributions.html

CustomOriginのCloudFront Distributionを作成するサンプルソースコードです。
https://gist.github.com/raw/704497/b05672822ffd658950511e4ab1b9be437518cec0/CreateCFDistributionWithCustomOrigin.cs

CloudFrontDistributionConfig にS3Originではなく、CustomOriginを作成して追加しているのがポイント。
customOrigin.DNSName に指定するサイトのDNS名を指定します。IPアドレスは指定できません。

                                                                                                • -

CreateDistributionRequest req = new CreateDistributionRequest();

CloudFrontDistributionConfig config = new CloudFrontDistributionConfig();

CustomOrigin customOrigin = new CustomOrigin();
customOrigin.DNSName = "www.your.site.com";
customOrigin.ProtocolPolicy = OriginProtocolPolicy.HttpOnly;

config.CustomOrigin = customOrigin;
config.Comment = "Test Custom Origine Distribution";
config.Enabled = true;

req.DistributionConfig = config;

                                                                                                                          • -

DistributionConfigとCustomOriginの形式については以下のページを参照してください。

DistributionConfig Complex Type - Amazon CloudFront API Reference
http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/index.html?DistributionConfigDatatype.html#CustomOriginChildElements