Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/S3/S3Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,19 @@ public function createPresignedRequest(CommandInterface $command, $expires, arra
{
$command = clone $command;
$command->getHandlerList()->remove('signer');
$request = \Aws\serialize($command);
$signing_name = $this->getSigningName($request->getUri()->getHost());

/** @var \Aws\Signature\SignatureInterface $signer */
$signer = call_user_func(
$this->getSignatureProvider(),
$this->getConfig('signature_version'),
$this->getConfig('signing_name'),
$signing_name,
$this->getConfig('signing_region')
);

return $signer->presign(
\Aws\serialize($command),
$request,
$this->getCredentials()->wait(),
$expires,
$options
Expand Down Expand Up @@ -638,6 +640,22 @@ private function getEncodingTypeMiddleware()
};
}

/**
* Special handling for when the service name is s3-object-lambda.
* So, if the host contains s3-object-lambda, then the service name
* returned is s3-object-lambda, otherwise the default signing service is returned.
* @param string $host The host to validate if is a s3-object-lambda URL.
* @return string returns the signing service name to be used
*/
private function getSigningName($host)
{
if (strpos( $host, 's3-object-lambda')) {
return 's3-object-lambda';
}

return $this->getConfig('signing_name');
}

/** @internal */
public static function _applyRetryConfig($value, $args, HandlerList $list)
{
Expand Down
1 change: 1 addition & 0 deletions src/Signature/SignatureProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SignatureProvider
private static $s3v4SignedServices = [
's3' => true,
's3control' => true,
's3-object-lambda' => true,
];

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/S3/S3ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ public function testCreatesPresignedUrlsWithSpecialCharactersWithPathStyle()
$this->assertArrayHasKey('X-Amz-Signature', $query);
}

public function testCreatesPresignedRequestsForObjectLambdaService()
{
/** @var S3Client $client */
$client = $this->getTestClient('S3', [
'region' => 'us-east-1',
'credentials' => ['key' => 'foo', 'secret' => 'bar']
]);
$command = $client->getCommand(
'GetObject',
[
'Bucket' => 'arn:aws:s3-object-lambda:us-east-1:123456789012:accesspoint/lambda-access-point',
'Key' => 'bar'
]
);
$url = (string) $client->createPresignedRequest($command, 1342138769)->getUri();
$this->assertStringStartsWith('https://lambda-access-point-123456789012.s3-object-lambda.us-east-1.amazonaws.com/bar?', $url);
$this->assertContains('X-Amz-Expires=', $url);
$this->assertContains('X-Amz-Credential=', $url);
$this->assertContains('X-Amz-Signature=', $url);
}

public function testRegistersStreamWrapper()
{
$s3 = $this->getTestClient('S3', ['region' => 'us-east-1']);
Expand Down
1 change: 1 addition & 0 deletions tests/Signature/SignatureProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function versionProvider()
['v4', 'Aws\Signature\SignatureV4', 'foo'],
['v4', 'Aws\Signature\S3SignatureV4', 's3'],
['v4', 'Aws\Signature\S3SignatureV4', 's3control'],
['v4', 'Aws\Signature\S3SignatureV4', 's3-object-lambda'],
['v4-unsigned-body', 'Aws\Signature\SignatureV4', 'foo'],
['anonymous', 'Aws\Signature\AnonymousSignature', 's3'],
];
Expand Down