签名版本4最长一周。在Python中,我做到了:
s3_client = boto3.client('s3',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
config=botocore.client.Config(signature_version='s3')
)
return s3_client.generate_presigned_url(
'get_object',
Params={
'Bucket': bucket_name,
'Key': key
},
ExpiresIn=400000000) # this is a max: ~ten years
但是对于Go我只发现了func (*Request) Presign:
req, _ := s3Client.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(bucketName),
Key: &key,
})
tenYears := time.Now().AddDate(10, 0, 0).Sub(time.Now())
url, err := req.Presign(tenYears)
此类URL的HTTP响应为:
AuthorizationQueryParametersError: X-Amz-Expires must be less than a week (in seconds); that is, the given X-Amz-Expires must be less than 604800 seconds.
多年以来,没有办法在Go中使用AWS SDK对URL进行预签名吗?
答案 0 :(得分:1)
如果您要对URL进行预签名超过一周,则您对预签名URL的用例无效。 According to the spec真的只有一个星期。
预签名URL通常用于仅将S3中的内容提供给经过身份验证的用户。