getSignedCookie([ 'url' => $resourceKey, 'expires' => $expires, 'private_key' => $privateKey, 'key_pair_id' => $keyPairId ]); return $result; } catch (AwsException $e) { return [ 'Error' => $e->getAwsErrorMessage() ]; } } function signACookie() { $resourceKey = 'https://d13l49jEXAMPLE.cloudfront.net/my-file.txt'; $expires = time() + 300; // 5 minutes (5 * 60 seconds) from now. $privateKey = dirname(__DIR__) . '/cloudfront/my-private-key.pem'; $keyPairId = 'AAPKAJIKZATYYYEXAMPLE'; $cloudFrontClient = new CloudFrontClient([ 'profile' => 'default', 'version' => '2018-06-18', 'region' => 'us-east-1' ]); $result = signCookie($cloudFrontClient, $resourceKey, $expires, $privateKey, $keyPairId); /* If successful, returns something like: CloudFront-Expires = 1589926678 CloudFront-Signature = Lv1DyC2q...2HPXaQ__ CloudFront-Key-Pair-Id = AAPKAJIKZATYYYEXAMPLE */ foreach($result as $key => $value) { echo $key . ' = ' . $value . "\n"; } } // Uncomment the following line to run this code in an AWS account. // signACookie(); // snippet-end:[cloudfront.php.signed_cookie.main] // snippet-end:[cloudfront.php.signed_cookie.complete] // snippet-sourcedescription:[SignCookie.php demonstrates how to grant users access to your private content using signed cookies and an Amazon CloudFront distribution.] // snippet-keyword:[PHP] // snippet-sourcesyntax:[php] // snippet-keyword:[AWS SDK for PHP v3] // snippet-keyword:[Code Sample] // snippet-keyword:[getSignedCookie] // snippet-keyword:[Amazon CloudFront] // snippet-service:[cloudfront] // snippet-sourcetype:[full-example] // snippet-sourcedate:[2020-05-20] // snippet-sourceauthor:[pccornel (AWS)]