Created
November 18, 2010 09:52
-
-
Save hayashih/704820 to your computer and use it in GitHub Desktop.
Create Amazon CloudFront Distribution use Custom Origin and Trusted Singer. Require AWS SDK for .NET http://aws.amazon.com/sdkfornet/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Amazon.CloudFront; | |
using Amazon.CloudFront.Model; | |
using System.Collections.Specialized; | |
using System.Configuration; | |
// Require AWS SDK for .NET http://aws.amazon.com/sdkfornet/ | |
namespace AWS_Test | |
{ | |
class Program | |
{ | |
static string accessKeyID = "Your AccessKey ID"; | |
static string secretAccessKeyID = "Your SecretAccessKey ID"; | |
static AmazonCloudFront cfClient = null; | |
static void Main(string[] args) | |
{ | |
using (cfClient = Amazon.AWSClientFactory.CreateAmazonCloudFrontClient(accessKeyID, secretAccessKeyID)) | |
{ | |
Console.WriteLine("Create CloudFront custom distribution with TrustedSinger"); | |
CreateCFDistributionWithCustomOriginAndTrustedSinger(); | |
Console.WriteLine("Finish"); | |
} | |
Console.WriteLine("Press any key to continue..."); | |
Console.Read(); | |
} | |
static void CreateCFDistributionWithCustomOriginAndTrustedSinger() | |
{ | |
try | |
{ | |
CreateDistributionRequest req = new CreateDistributionRequest(); | |
UrlTrustedSigners trustedSigners = new UrlTrustedSigners(); | |
trustedSigners.EnableSelf = true; | |
trustedSigners.WithAwsAccountNumbers("AWS Account Numbers"); | |
CloudFrontDistributionConfig config = new CloudFrontDistributionConfig(); | |
CustomOrigin customOrigin = new CustomOrigin(); | |
customOrigin.DNSName = "www.your.site.com"; | |
customOrigin.ProtocolPolicy = OriginProtocolPolicy.HttpOnly; | |
config.CustomOrigin = customOrigin; | |
config.Enabled = true; | |
config.TrustedSigners = trustedSigners; | |
req.DistributionConfig = config; | |
var response = cfClient.CreateDistribution(req); | |
String xml = response.XML; | |
Console.WriteLine(xml); | |
} | |
catch (AmazonCloudFrontException cfEx) | |
{ | |
Console.WriteLine("An Error, number {0}, occurred when create cloud distribution with the message '{1}", cfEx.ErrorCode, cfEx.Message); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("UnknownError:{0}", ex.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment