CloudFront

Amazon CloudFront CDN Service (http://aws.amazon.com/cloudfront)

Version

2009.04.29

Copyright

2006-2009 LifeNexus Digital, Inc., and contributors.

License

Simplified BSD Licensehttp://opensource.org/licenses/bsd-license.php

See Also

Tarzanhttp://tarzan-aws.com
Amazon CloudFronthttp://aws.amazon.com/cloudfront

Constants

EC2_DEFAULT_URL

Specify the default queue URL.

AmazonCloudFront

Container for all Amazon CloudFront-related methods.  Inherits additional methods from TarzanCore.

Extends

TarzanCore

Example Usage

require_once('tarzan.class.php');

// Instantiate a new AmazonCloudFront object using the settings from the config.inc.php file.
$cdn = new AmazonCloudFront();

// Instantiate a new AmazonCloudFront object using these specific settings.
$cdn = new AmazonCloudFront($key, $secret_key);

Properties

base_xml

The base content to use for generating the DistributionConfig XML.

Functions

__construct()

public function __construct($key =  null,
$secret_key =  null)

The constructor

Access

public

Parameters

keystring (Optional) Your Amazon API Key.  If blank, it will look for the AWS_KEY constant.
secret_keystring (Optional) Your Amazon API Secret Key.  If blank, it will look for the AWS_SECRET_KEY constant.

Returns

boolean false if no valid values are set, otherwise true.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/__construct.phps

authenticate()

public function authenticate($method =  HTTP_GET,
$path =  null,
$opt =  null,
$xml =  null,
$etag =  null)

Authenticates a connection to CloudFront.  This should not be used directly unless you’re writing custom methods for this class.

Access

public

Parameters

methodstring (Required) The HTTP method to use to connect.  Accepts HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE, and HTTP_HEAD.
pathstring (Optional) The endpoint path to make requests to.
optarray (Optional) Associative array of parameters for authenticating.  See the individual methods for allowed keys.
xmlstring (Optional) The XML body content to send along in the request.
etagstring (Optional) The ETag value to pass along with the If-Match HTTP header.

Returns

TarzanHTTPResponse object

See Also

http://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/RESTAuthentication.html

disable_ssl()

public function disable_ssl()

Throws an error because SSL is required for the CloudFront service.

Access

public

Returns

void

generate_config_xml()

public function generate_config_xml($origin,  
$caller_reference,  
$opt =  null)

Used to generate the Distribution Config XML used in create_distribution() and set_distribution_config().

Access

public

Parameters

originstring (Required) The source S3 bucket to use for the CloudFront distribution.
caller_referencestring (Required) A unique identifier for the request.  Must be generated on your own.  A time stamp or hash is a good example.
optarray (Optional) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

CNAMEstring | array (Optional) A DNS CNAME to use to map to the CloudFront distribution.  If setting more than one, use an indexed array.  Supports 1-10 CNAMEs.
Commentinteger (Optional) A comment to apply to the distribution.  Cannot exceed 128 characters.
Enabledstring (Optional) Defaults to true.  Use this to set Enabled to false.

Returns

String DistributionConfig XML document.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/generate_config_xml.phps
Relatedgenerate_config_xml(), update_config_xml(), remove_cname()

update_config_xml()

public function update_config_xml($xml,  
$opt =  null)

Used to update an existing DistributionConfig XML document.

Access

public

Parameters

xmlSimpleXMLElement | TarzanHTTPResponse | string (Required) The source DistributionConfig XML to make updates to.  Can be the SimpleXMLElement body of a get_distribution_config() response, the entire TarzanHTTPResponse of a get_distribution_config() response, or a string of XML generated by generate_config_xml() or update_config_xml().
optarray (Optional) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

CNAMEstring | array (Optional) This (these) value(s) will be ADDED to the existing list of CNAME values.  To remove a CNAME value, see remove_cname().
Commentinteger (Optional) This value will replace the existing value for ‘Comment’.  Cannot exceed 128 characters.
Enabledstring (Optional) This value will replace the existing value for ‘Enabled’.

Returns

String DistributionConfig XML document.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/update_config_xml.phps
Relatedgenerate_config_xml(), update_config_xml(), remove_cname()

remove_cname()

public function remove_cname($xml,
$cname)

Used to remove one or more CNAMEs from a DistributionConfig XML document.

Access

public

Parameters

xmlSimpleXMLElement | TarzanHTTPResponse | string (Required) The source DistributionConfig XML to make updates to.  Can be the SimpleXMLElement body of a get_distribution_config() response, the entire TarzanHTTPResponse of a get_distribution_config() response, or a string of XML generated by generate_config_xml() or update_config_xml().
cnamestring | array (Optional) This (these) value(s) will be REMOVED from the existing list of CNAME values.  To add a CNAME value, see update_config_xml().

Returns

String DistributionConfig XML document.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/remove_cname.phps
Relatedgenerate_config_xml(), update_config_xml(), remove_cname()

create_distribution()

public function create_distribution($origin,  
$caller_reference,  
$opt =  null)

The response echoes the DistributionConfig element and returns other metadata about the distribution.  For more information, see Parts of a Basic Distribution.  It takes a short time for CloudFront to propagate your new distribution’s information throughout the CloudFront system.  For more information, see Eventual Consistency.  You can have up to 100 distributions in the Amazon CloudFront system.

Access

public

Parameters

originstring (Required) The source S3 bucket to use for the CloudFront distribution.
caller_referenceinteger (Required) A unique identifier for the request.  Must be generated on your own.  A timestamp could be good.
optarray (Optional) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

CNAMEstring | array (Optional) A DNS CNAME to use to map to the CloudFront distribution.  If setting more than one, use an indexed array.  Supports 1-10 CNAMEs.
Commentinteger (Optional) A comment to apply to the distribution.  Cannot exceed 128 characters.
Enabledstring (Optional) Defaults to true.  Use this to set Enabled to false.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/CreateDistribution.html
Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/create_distribution.phps
Relatedcreate_distribution(), list_distributions(), get_distribution_info(), delete_distribution()

list_distributions()

public function list_distributions($opt =  null)

Gets a list of your distributions.  By default, your entire list of distributions is returned in one single page.  If the list is long, you can paginate it using the MaxItems and Marker parameters.

Access

public

Parameters

optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

Markerstring (Optional) Use this when paginating results to indicate where in your list of distributions to begin.  The results include distributions in the list that occur after the marker.  To get the next page of results, set the Marker to the value of the NextMarker from the current page’s response (which is also the ID of the last distribution on that page).
MaxItemsinteger (Optional) The maximum number of distributions you want in the response body.  Maximum of 100.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/ListDistributions.html
Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/list_distributions.phps
Relatedcreate_distribution(), list_distributions(), get_distribution_info(), delete_distribution()

get_distribution_info()

public function get_distribution_info($distribution_id,  
$opt =  null)

Gets information about a given distribution.

Access

public

Parameters

distribution_idstring (Required) The distribution ID returned from create_distribution() or list_distributions().
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/GetDistribution.html
Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/get_distribution_info.phps
Relatedcreate_distribution(), list_distributions(), get_distribution_info(), delete_distribution()

delete_distribution()

public function delete_distribution($distribution_id,  
$etag,  
$opt =  null)

Deletes a disabled distribution.  If you haven’t disabled the distribution, Amazon CloudFront returns a DistributionNotDisabled error.  Use set_distribution_config() to disable a distribution before attempting to delete.

Access

public

Parameters

distribution_idstring (Required) The distribution ID returned from create_distribution() or list_distributions().
etagstring (Required) The ETag header value retrieved from a call to get_distribution_config().
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/DeleteDistribution.html
Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/delete_distribution.phps
Relatedcreate_distribution(), list_distributions(), get_distribution_info(), delete_distribution()

get_distribution_config()

public function get_distribution_config($distribution_id,  
$opt =  null)

Gets the current distribution config information for a given distribution ID.

Access

public

Parameters

distribution_idstring (Required) The distribution ID returned from create_distribution() or list_distributions().
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/GetConfig.html
Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/get_distribution_config.phps
Relatedget_distribution_config(), set_distribution_config()

set_distribution_config()

public function set_distribution_config($distribution_id,  
$xml,  
$etag,  
$opt =  null)

Sets a new distribution config for a given distribution ID.

Access

public

Parameters

distribution_idstring (Required) The distribution ID returned from create_distribution() or list_distributions().
xmlstring (Required) The DistributionConfig XML generated by generate_config_xml() or update_config_xml().
etagstring (Required) The ETag header value retrieved from a call to get_distribution_config().
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AmazonCloudFront/2008-06-30/DeveloperGuide/PutConfig.html
Example Usagehttp://tarzan-aws.com/docs/examples/cloudfront/set_distribution_config.phps
Relatedget_distribution_config(), set_distribution_config()