getSignedCookie([ 'policy' => $customPolicy, 'private_key' => $privateKey, 'key_pair_id' => $keyPairId ]); return $result; } catch (AwsException $e) { return [ 'Error' => $e->getAwsErrorMessage() ]; } } function signACookiePolicy() { $resourceKey = 'https://d13l49jEXAMPLE.cloudfront.net/my-file.txt'; $expires = time() + 300; // 5 minutes (5 * 60 seconds) from now. $customPolicy = << 'default', 'version' => '2018-06-18', 'region' => 'us-east-1' ]); $result = signCookiePolicy($cloudFrontClient, $customPolicy, $privateKey, $keyPairId); /* If successful, returns something like: CloudFront-Policy = eyJTdGF0...fX19XX0_ CloudFront-Signature = RowqEQWZ...N8vetw__ 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. // signACookiePolicy(); // snippet-end:[cloudfront.php.signed_cookie_policy.main] // snippet-end:[cloudfront.php.signed_cookie_policy.complete] // snippet-sourcedescription:[SignCookiePolicy.php demonstrates how to grant users access to your private content using signed cookies, a custom policy, 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-18] // snippet-sourceauthor:[pccornel (AWS)]