简体   繁体   English

存储桶级别的Amazon S3安全URL

[英]Amazon S3 secure URL at the bucket level

I want to be able to serve URLs to client that are "signed" and so, are only relevant to 24 hours (for example). 我希望能够为“已签名”的客户端提供URL,因此仅与24小时相关(例如)。 However, I don't want to call S3 for every URL generated: 但是,我不想为生成的每个URL调用S3:

AWS::S3::S3Object.new(bucket, name).url_for(:read, :secure => true, :expires => expires_in).to_s

Instead, I want to generate the URL by myself (I have the file name and the bucket link, I can build it myself). 相反,我想自己生成URL(我有文件名和存储桶链接,我可以自己构建)。

However, I want to sign the url at the bucket level (say, once a day for all the files in a given bucket). 但是,我想在桶级别对URL进行签名(例如,对于给定存储桶中的所有文件,每天一次)。 is this possible? 这可能吗?

When you create a pre-signed URL, that is done completely locally. 创建预签名URL时,完全在本地完成。 You could do it "by yourself", but it is much easier to use the SDK, and there would be no practical diferences. 你可以“自己动手”,但使用SDK要容易得多,并没有实际的差异。 See that there is no "sign" action on the S3 API . 请注意S3 API上没有“签名”操作。

However, you can not sign at the "bucket level", as signature is checked per-object. 但是,您无法在“桶级别”进行签名,因为每个对象都会检查签名。 I believe signing a whole bucket would not be feasible. 我认为签署一个整桶是不可行的。

Sorry I do not have ruby code for this only Java... 对不起我没有这个只有Java的ruby代码...

But you will not be able to get a presigned url for the whole bucket, only each file. 但是你将无法获得整个存储桶的预分配网址,只能获得每个文件。

Here is the function I created. 这是我创建的功能。 This will print everything for you. 这将为您打印一切。 Does the process make sense? 这个过程有意义吗?

private static URI GetURL(AmazonS3Client amazonS3Client, S3ObjectSummary s3ObjectSummary) throws URISyntaxException {
    return amazonS3Client.generatePresignedUrl(
            new GeneratePresignedUrlRequest(s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey())
            .withMethod(HttpMethod.GET)
            .withExpiration(GetExperation())).toURI();
}

public static void run(String accessKey, String secretKey, String bucketName) {

    AmazonS3Client amazonS3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
    amazonS3Client.listObjects(bucketName)
            .getObjectSummaries()
            .stream()
            .forEach(s3ObjectSummary
                    -> System.out.println(GetURL(amazonS3Client, s3ObjectSummary).toString()));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM