Amazon CloudFront
Developer Guide (API Version 2010-11-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Creating a Distribution with a Custom Origin

You can create a distribution that uses either a custom origin or an Amazon S3 origin. This section describes how to create a distribution with a custom origin. To learn how to create a distribution with an Amazon S3 origin, see Start Using CloudFront with Amazon S3 in the Amazon CloudFront Getting Started Guide.

For a basic description of origins and the features supported for use with custom origins, see The Origin Server.

The following table describes the overall process for creating a distribution with a custom origin.

Process for Creating a Distribution with a Custom Origin

1

Review the section called “Requirements and Recommendations for Using Amazon EC2 and Other Custom Origins”.

2

Upload your content to your origin server and verify that it is accessible.

3

Create an Amazon CloudFront distribution.

4

Use the Amazon CloudFront domain name to reference content in your web pages or applications.

Upload Your Content to Your Origin Server

The content you deliver with CloudFront will be stored on a server referred to as an origin server. The origin server might be an Amazon Elastic Compute Cloud (EC2) instance, or it might be a server you manage privately.

Content can consist of just about any type of object, including images and videos. Before creating your Amazon CloudFront distribution, load the content you want to distribute on your custom origin server. You should also make sure that the content is accessible.

[Caution]Caution

You are responsible for ensuring the security of your origin server. You must ensure that CloudFront has permission to access the server, and you must be sure that the security settings are appropriate to safeguard your content.

Create an Amazon CloudFront Distribution

To create a distribution with a custom origin, you can use either the AWS Management Console or the CloudFront API. The following sections describe both methods.

Using the AWS Management Console to Create a Distribution

To create an Amazon CloudFront distribution

  1. Sign in to the AWS Management Console and open the Amazon CloudFront console at https://console.aws.amazon.com/cloudfront/.

  2. Click Create Distribution.

    Create Distribution
  3. From the Create Distribution Wizard, choose Download and Custom Origin.

    [Note]Note

    Currently, you cannot use a custom origin with a streaming distribution. CloudFront supports only Amazon S3 origin servers for streaming distributions.

    Create Distribution Wizard
  4. Under Custom Origin, specify the following information:

    1. For Origin DNS Name, enter the origin to associate with the distribution. For example, www.example.com.

    2. Select the Protocol Policy to apply to your origin. If you select HTTP Only, CloudFront uses only HTTP to access the origin. If you specify Match Viewer, CloudFront fetches data from your origin using HTTP or HTTPS, based on the protocol of the viewer request.

    3. Specify which HTTP Port the custom origin listens on. The default value is port 80.

    4. If you selected Match Viewer as the Protocol Policy, you must also specify the HTTPS Port the custom origin listens on. The default value is port 443.

  5. Click Continue.

    Create Distribution Wizard
  6. Next, specify the distribution details:

    1. For Allowed Connections, to restrict access to your distribution to only HTTPS requests, select HTTPS Only. Otherwise, select HTTP and HTTPS to use either protocol to serve the request. For more information, see Creating Secure HTTPS Connections.

    2. If your distribution will use a CNAME, for CNAMEs, enter the CNAME alias you want to associate with this distribution. You can have up to 10 CNAME aliases per distribution. For more information, see Using CNAMEs.

    3. If you want to use a default root object with your distribution, for Default Root Object enter the default root object to associate with the distribution. For example, index.html. For more information, see Creating a Default Root Object.

    4. If you want to enable logging, for Logging select On, and then from Select Log Bucket, select the Amazon S3 bucket to which you want to save your logs. Alternatively, you can type the bucket name in the Specify Log Bucket field. Type the log file prefix in the Log Prefix field. For more information, see Access Logs.

    5. In Comments, you can enter any comments you want to include about the distribution.

    6. For the Distribution Status, select Enabled if you want the distribution to accept end-user requests for content as soon as it is deployed. Otherwise, if you prefer to enable the distribution later, choose Disabled. For more information, see Enabled or Disabled.

  7. To review your distribution settings, click Continue.

  8. If you are satisfied with the distribution settings, click Create Distribution.

After creating the distribution, it might take a few minutes for the distribution to deploy. The distribution's current status is displayed in the console under Status. InProgress indicates that the distribution is not yet fully deployed.

[Note]Note

Even if the distribution's status is Deployed, you still must enable the distribution for use before end users can retrieve content. For more information, see Enabled or Disabled.

When your distribution is deployed, you are ready to reference your content with your new Amazon CloudFront URL or CNAME, as described in Reference Content in Your Web Pages or Applications .

Using the CloudFront API to Create a Distribution

To create an Amazon CloudFront distribution

  • Send a POST request on the 2010-11-01/distribution resource. The request body must include an XML document with a DistributionConfig element.

The response echoes the DistributionConfig element and returns other metadata about the distribution. (For more information about the parts of a distribution, see Parts of a Distribution.)

For example, you would post the following request and receive the following response. The request and response elements are described in DistributionConfig Complex Type in the Amazon CloudFront API Reference.

Example Request

POST /2010-11-01/distribution HTTP/1.1
Host: cloudfront.amazonaws.com
Authorization: [AWS authentication string]
Date: Thu, 19 Nov 2009 19:37:58 GMT
[Other required headers]

<?xml version="1.0" encoding="UTF-8"?>
<DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
   <CustomOrigin>
      <DNSName>www.example.com</DNSName>
      <HTTPPort>80</HTTPPort>
      <HTTPSPort>443</HTTPSPort>
      <OriginProtocolPolicy>match-viewer</OriginProtocolPolicy>
   </CustomOrigin>
   <CallerReference>20091130090000</CallerReference>
   <CNAME>beagles.com</CNAME>
   <Comment>My comments</Comment>
   <Enabled>true</Enabled>
   <Logging>
      <Bucket>myawslogbucket.s3.amazonaws.com</Bucket>
      <Prefix>myprefix/</Prefix>
   </Logging>
</DistributionConfig>

For information about the headers required with every request, see REST Requests.

Example Response

HTTP/1.1 201 Created
201 Created
Location: [URI of new distribution]
x-amz-request-id: [Request ID]

<?xml version="1.0" encoding="UTF-8"?>
<Distribution xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
   <Id>the distribution ID</Id>
   <Status>InProgress</Status>
   <LastModifiedTime>2009-11-19T19:37:58Z</LastModifiedTime>
   <DomainName>d60EXAMPLEfxaaqy9.cloudfront.net</DomainName>
   <DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
      <CustomOrigin>
         <DNSName>www.example.com</DNSName>
         <HTTPPort>80</HTTPPort>
         <HTTPSPort>443</HTTPSPort>
         <OriginProtocolPolicy>match-viewer</OriginProtocolPolicy>
      </CustomOrigin>
      <CallerReference>20091130090000</CallerReference>
      <CNAME>beagles.com</CNAME>
      <Comment>My comments</Comment>
      <Enabled>true</Enabled>
      <Logging>
         <Bucket>myawslogbucket.s3.amazonaws.com</Bucket>
         <Prefix>myprefix/</Prefix>
      </Logging>
   </DistributionConfig>
</Distribution>

After creating the distribution, it might take a few minutes for the distribution to deploy. You can monitor the progress by polling for status as described in the section, Monitor Your CloudFront Distribution to Check Its Status.

Monitor Your CloudFront Distribution to Check Its Status

To get status information about a distribution, you send a GET request on the 2010-11-01/distribution/Distribution ID resource. Your request and the response might look like the following examples.

Example Request

						
GET /2010-11-01/distribution/<distribution ID> HTTP/1.1
Host: cloudfront.amazonaws.com
Authorization: [AWS authentication string]
Date: [time stamp]
[Other required headers]

Example Response

200 OK
ETag: [ETag value to use later when doing a PUT or DELETE.]
x-amz-request-id: request_id

<Distribution xmlns="http://cloudfront.amazonaws.com/doc/</">
   <Id>the distribution ID</Id>
   <Status>Deployed</Status>
   <LastModifiedTime>2009-11-19T19:37:58Z</LastModifiedTime>
   <DomainName>d60EXAMPLEfxaaqy9.cloudfront.net</DomainName>
   <DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"
      <CustomOrigin>
         <DNSName>www.example.com</DNSName>
         <HTTPPort>80</HTTPPort>
         <OriginProtocolPolicy>http-only</OriginProtocolPolicy>
      </CustomOrigin>
      <CallerReference>20091130090000</CallerReference>
      <CNAME>beagles.com</CNAME>
      <Comment>My comments</Comment>
      <Enabled>true</Enabled>
      <Logging>
         <Bucket>myawslogbucket.s3.amazonaws.com</Bucket>
         <Prefix>myprefix/</Prefix>
      </Logging>
   </DistributionConfig>
</Distribution>
	

For more information on the ETag element, see Updating a Distribution's Configuration.


When Enabled becomes true and Status changes from InProgress to Deployed, your distribution is ready. Also, as shown in the preceding example, the automatically generated domain name for your distribution is visible. If you chose to use a CNAME, it is also visible. It generally takes less than 15 minutes for a distribution to deploy.

You are ready to reference your content with your new Amazon CloudFront URL or CNAME.

Reference Content in Your Web Pages or Applications

After you've created your distribution, Amazon CloudFront knows where your origin server is, and you know the domain name associated with the distribution. You can create a link to that domain name and CloudFront will serve it to your web page or application.

[Note]Note

You must wait until the distribution's state is Deployed before testing your links.

To link to your object

  1. Copy the following HTML into a new file and replace the domain name with your distribution's domain name and object name with the name of your content.

    <html>
    <head>My CloudFront Test</head>
    <body>
    <p>My text content goes here.</p>
    <p><img src="http://<domain name>/<object name>" alt="my test image"/>
    </body>
    </html>

    For example, if your domain name was d604721EXAMPLE9.cloudfront.net and your object was image.jpg, the URL for the link would be: http://d604721EXAMPLE9.cloudfront.net/image.jpg.

    If your object is in a folder on your origin server, then the folder must also be included in the URL. For example, if image.jpg was located in your origin images folder, then the URL would be: http://d604721EXAMPLE9.cloudfront.net/images/image.jpg.

  2. Save the changes to your file.

  3. Open your web page in a browser to ensure you can see your image.

The browser returns your page with the embedded image file, served from the edge location that CloudFront determined was appropriate to serve the object.

Congratulations! You've used CloudFront to serve an image from a custom origin.