【发布时间】:2020-12-25 19:38:59
【问题描述】:
在 SDK 文档(链接:https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html#_createPresignedRequest)中,$expires 参数应表示 URL 的过期时间。
因此,如果我指定 2 分钟作为过期时间,则 2 分钟后 URL 应该是无效的。我的代码是这样的
<?php
$s3 = $this->cloudProvider->getClient(); // S3 client
$cmd = $s3->getCommand(
'GetObject',
[
'Bucket' => $this->getSdkBucket(), // Bucket name
'Key' => "$s3Name",
]
);
$urlReq = $s3->createPresignedRequest($cmd, $expirationTime); // $expirationTime is a Unix timestamp
我得到了具有正确到期时间的 url(在我的情况下,客户希望它是会话到期时间,会话时间是 4 小时)
X-Amz-Content-Sha256=UNSIGNED-PAYLOAD
&X-Amz-Security-Token=long_string_goes_here
&X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential=another_string_goes_here
&X-Amz-Date=20200907T110127Z
&X-Amz-SignedHeaders=host
&X-Amz-Expires=14400 // This decreases depending on how long the user is logged in - max 4hrs
&X-Amz-Signature=another_string_here
问题是这个网址会在4小时后生效。
根据我在此答案中阅读的有关到期时间 (https://stackoverflow.com/a/57792699/629127) 的内容,该 URL 的有效期为 6 小时到 7 天,具体取决于用于生成它的凭据。
我正在使用 IAM 凭证(ECS 提供商)。
这是否意味着无论我在到期变量中输入什么值,我都无法使链接在该时间段内有效?
【问题讨论】:
标签: amazon-web-services amazon-s3 aws-php-sdk