Sovled! Thanks to @Michael - sqlbot. By using a custom policy I can return any image dimensions I want including the original size using one signed url. In case anyone else has this issue here's how I did it:
My php code to generate the signed url:
public static function signedImageUrl($resource)
{
// Build Url
$url = self::CLOUDFRONT_BASE . ltrim($resource, '/') . '?w=*&h=*';
// Create a CloudFront Client
$client = new CloudFrontClient([
'version' => '2014-11-06',
'region' => 'us-east-2'
]);
// Set up parameter values for the resource
$expires = time() + 300;
// Policy
$policy = '{
"Statement": [
{
"Resource":"' . $url . '",
"Condition":{
"DateLessThan":{"AWS:EpochTime":' . $expires . '}
}
}
]
}';
// Create a signed URL for the resource using the canned policy
$signedUrlCannedPolicy = $client->getSignedUrl([
'url' => $url,
'policy' => $policy,
'private_key' => env('AWS_CLOUDFRONT_PRIVATE_KEY_PATH'),
'key_pair_id' => env('AWS_CLOUDFRONT_KEY_PAIR_ID')
]);
return $signedUrlCannedPolicy;
}
Where CLOUDFRONT_BASE is the .cloudfront.net/ domain for my cloudfront distribution, and $resource is the filename (e.g. my_profile_image.png)
At this point I get my signed image and can then modify the w and h query parameters on the client to my hearts content. My lambda function is fired on the cloudfront ViewerRequest event and will direct cloudfront to load either the image with specified dimensions, or to load the original image if w and h are both *.
*"anywhere in the string" when generating a signed URL using a custom policy (not a canned policy) which should allow something likehttps://example.com/images/funny/cat.png?size=*in the policy document to authorize any matching request. Have you tried that approach?