create_distribution ( $origin, $caller_reference, $opt )

Creates an Amazon CloudFront distribution. You can have up to 100 distributions in the Amazon CloudFront system.

For an Adobe Real-Time Messaging Protocol (RTMP) streaming distribution, set the Streaming option to true.

Access

public

Parameters

Parameter

Type

Required

Description

$origin

string

Required

The source to use for the Amazon CloudFront distribution. Use an Amazon S3 bucket name, or a fully-qualified non-S3 domain name prefixed with http:// or https://.

$caller_reference

string

Required

A unique identifier for the request. A timestamp-appended string is recommended.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • CNAME - string|array - Optional - A DNS CNAME to use to map to the Amazon CloudFront distribution. If setting more than one, use an indexed array. Supports 1-10 CNAMEs.
  • Comment - string - Optional - A comment to apply to the distribution. Cannot exceed 128 characters.
  • DefaultRootObject - string - Optional - The file to load when someone accesses the root of the Amazon CloudFront domain (e.g., index.html).
  • Enabled - string - Optional - A value of true will enable the distribution. A value of false will disable it. The default value is true.
  • OriginAccessIdentity - string - Optional - The origin access identity (OAI) associated with this distribution. Use the Identity ID from the OAI, not the CanonicalId. Requires an S3 origin.
  • OriginProtocolPolicy - string - Optional - The origin protocol policy to apply to your origin. If you specify http-only, CloudFront will use HTTP only to access the origin. If you specify match-viewer, CloudFront will fetch from your origin using HTTP or HTTPS, based on the protocol of the viewer request. [Allowed values: http-only, match-viewer]. The default value is match-viewer. Requires a non-S3 origin.
  • Streaming - boolean - Optional - Whether or not this should be for a streaming distribution. A value of true creates a streaming distribution. A value of false creates a standard distribution. The default value is false.
  • Logging - array - Optional - Controls whether access logs are written for the distribution. If you want to turn on access logs, include this element; if you want to turn off access logs, remove this element.
  • TrustedSigners - array - Optional - An array of AWS account numbers for users who are trusted signers. Explicity add the value Self to the array to add your own account as a trusted signer.
  • RequiredProtocols - string - Optional - Use this element to restrict access to your distribution solely to HTTPS requests. Without this element, CloudFront can use any available protocol to serve the request.
  • CachingBehavior - array - Optional - Determines the minimum TTL for objects in the CloudFront cache. This value specifies a lower bound for values in the headers for an object, for example, in the Cache-Control max-age directive.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Create a new CloudFront distribution with logging and CNAMEs enabled.

// Create a new CloudFront distribution from an S3 bucket.
$cdn = new AmazonCloudFront();

$response = $cdn->create_distribution(''my-bucket'', 'AWSPHPSDKCFDemo01', array(
	'Enabled' => true,
	'Comment' => 'This is my sample comment',
	'CNAME' => array(
		'cname-php-10.example.com',
		'cname-php-20.example.com'
	),
	'Logging' => array(
		'Bucket' => 'my-bucket-logs',
		'Prefix' => 'log_'
	)
));

// Success?
var_dump($response->isOK());
Result:
bool(true)

Create a new streaming CloudFront distribution with logging and CNAMEs enabled.

// Create a new CloudFront distribution from an S3 bucket.
$cdn = new AmazonCloudFront();

$response = $cdn->create_distribution('my-bucket', 'php1' . time(), array(
	'Enabled' => true,
	'Comment' => 'This is my sample comment',
	'CNAME' => 'cname-php-3.example.com',
	'Logging' => array(
		'Bucket' => 'my-bucket-logs',
		'Prefix' => 'log_',
	),
	'RequiredProtocols' => 'https',
	'Streaming' => true,
	'OriginAccessIdentity' => 'E3HV63EQPFPPOA',
	'TrustedSigners' => array(
		'Self',
		'178280267275',
	),
	'CachingBehavior' => array(
		'MinTTL' => '30 minutes',
	),
));

// Success?
var_dump($response->isOK());
Result:
bool(true)

Create a new CloudFront distribution from a non-S3 origin.

// Create a new CloudFront distribution from an S3 bucket.
$cdn = new AmazonCloudFront();

$response = $cdn->create_distribution('http://'www.example.com'', 'php2' . time(), array(
	'Enabled' => true,
	'Comment' => 'This is my sample comment',
	'OriginProtocolPolicy' => 'match-viewer',
	'CNAME' => array(
		'cname-php-4.example.com',
		'cname-php-5.example.com'
	),
	'Logging' => array(
		'Bucket' => 'my-bucket-logs',
		'Prefix' => 'nonS3_'
	)
));

// Success?
var_dump($response->isOK());
Result:
bool(true)

Related Methods

See Also

Source

Method defined in services/cloudfront.class.php | Toggle source view (11 lines) | View on GitHub

public function create_distribution($origin, $caller_reference, $opt = null)
{
    if (!$opt) $opt = array();

    $xml = $this->generate_config_xml($origin, $caller_reference, $opt);
    $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');

    $opt = array_merge($opt, array('path' => $path, 'xml' => $xml));

    return $this->authenticate('POST', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback