【发布时间】:2022-02-03 03:31:02
【问题描述】:
我目前正在使用 S3,需要提取一个流式传输超时的 S3 资源,以便客户端在特定时间后无法使用该 URL。
- 我已经使用了“Presigned Object URL Using AWS SDK for .NET”文档中提供的一些代码。
- 代码将提供一个临时 URL,任何人都可以使用该 URL 下载 S3 资源...但在特定的时间限制内。
- 我还使用了适用于 Visual Studio 的 Amazon S3 Explorer,但它不支持为嵌入 AWSKMS 密钥的资源生成 URL。
- 还尝试删除 S3 文件夹的 KMS 密钥,但这会引发错误。
如果有删除 KMS 密钥的可能链接,您是否也可以将其包含在您的答案中。
//Code Start
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
namespace URLDownload
{
public class Class1
{
private const string bucketName = "some-value";
private const string objectKey = "some-value";
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USEast1;
private static IAmazonS3 s3Client;
public static void Main()
{
s3Client = new AmazonS3Client(bucketRegion);
string urlString = GeneratePreSignedURL();
Console.WriteLine(urlString);
Console.Read();
}
static string GeneratePreSignedURL()
{
string urlString = "";
try
{
//ServerSideEncryptionMethod ssem = new ServerSideEncryptionMethod("AWSKMS");
GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = objectKey,
Expires = DateTime.Now.AddMinutes(5),
Verb = 0,
ServerSideEncryptionKeyManagementServiceKeyId = "some-value",
ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS
};
urlString = s3Client.GetPreSignedURL(request1);
}
catch (AmazonS3Exception e)
{
Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
}
catch (Exception e)
{
Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
}
return urlString;
}
}
}
SignatureDoesNotMatch
我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。
AKIA347A6YXQ3XM4JQ7A
这是我在尝试访问生成的 URL 时遇到的错误,这可能是因为 AWSKMS 身份验证存在问题。
【问题讨论】: