Skip to content

Instantly share code, notes, and snippets.

@hayashih
Created November 18, 2010 01:37
Show Gist options
  • Save hayashih/704497 to your computer and use it in GitHub Desktop.
Save hayashih/704497 to your computer and use it in GitHub Desktop.
Create Amazon CloudFront Distribution use Custom Origin. Require AWS SDK for .NET http://aws.amazon.com/sdkfornet/
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 Secret AccessKey ID ";
static AmazonCloudFront cfClient = null;
static void Main(string[] args)
{
using (cfClient = Amazon.AWSClientFactory.CreateAmazonCloudFrontClient(accessKeyID, secretAccessKeyID))
{
Console.WriteLine("Create CloudFront custom distribution");
CreateCFDistributionWithCustomOrigin();
Console.WriteLine("Finish");
}
Console.WriteLine("Press any key to continue...");
Console.Read();
}
static void CreateCFDistributionWithCustomOrigin()
{
try
{
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;
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