Installation guide

A more robust way to connect to Amazon CloudFront is through the service builder. This allows you to specify
credentials and other configuration settings in a configuration file. These settings can then be shared across all
clients so that you only have to specify your settings once.
use Aws\Common\Aws;
// Create a service builder using a configuration file
$aws = Aws::factory('/path/to/my_config.json');
// Get the client from the builder by namespace
$client = $aws->get('CloudFront');
Signing CloudFront URLs for Private Distributions
Signed URLs allow you to provide users access to your private content. A signed URL includes additional
information (e.g., expiration time) that gives you more control over access to your content. This additional
information appears in a policy statement, which is based on either a canned policy or a custom policy. For
information about how to set up private distributions and why you need to sign URLs, please read the Serving
Private Content through CloudFront section of the CloudFront Developer Guide.
You can sign a URL using the CloudFront client in the SDK. First you must make sure to provide your CloudFront
Private Key and Key Pair ID to the CloudFront client.
<?php
$cloudFront = CloudFrontClient::factory(array(
'private_key' => '/path/to/your/cloudfront-private-key.pem',
'key_pair_id' => '<cloudfront key pair id>',
));
You can alternatively specify the Private Key and Key Pair ID in your AWS config file and use the service builder to
instantiate the CloudFront client. The following is an example config file that specifies the CloudFront key
information.
<?php return array(
'includes' => array('_aws'),
'services' => array(
'default_settings' => array(
'params' => array(
'key' => '<aws access key>',
'secret' => '<aws secret key>',
'region' => 'us-west-2'
)
),
'cloudfront' => array(
'extends' => 'cloudfront',
'params' => array(
'private_key' => '/path/to/your/cloudfront-private-key.pem',
'key_pair_id' => '<cloudfront key pair id>'
)
)
)
);
You can sign a CloudFront URL for a video resource using either a canned or custom policy.
// Setup parameter values for the resource
$streamHostUrl = 'rtmp://example-distribution.cloudfront.net';
$resourceKey = 'videos/example.mp4';
$expires = time() + 300;
// Create a signed URL for the resource using the canned policy
$signedUrlCannedPolicy = $cloudFront->getSignedUrl(array(
Amazon CloudFront (2012-05-05)
56