使用AWS S3 Java SDK,确定授权(访问密钥和秘密密钥)是否正确的最快方法是什么? [英] Using the AWS S3 Java SDK, what is the fastest way to determine if the authorization (access key and secret key) is correct?

查看:430
本文介绍了使用AWS S3 Java SDK,确定授权(访问密钥和秘密密钥)是否正确的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种快速的方法来确定针对AWS S3的授权(访问密钥和秘密密钥)是否正确.

I need a quick way to determine if the authorization (access key and secret key) is correct for AWS S3.

我发现了一个较慢的解决方案:调用AmazonS3Client.getS3AccountOwner将导致签署请求并将其发送到AWS,如果您的访问密钥/秘密密钥不正确,则会失败.不幸的是,这需要200-300毫秒.

I have found a slow solution: Calling AmazonS3Client.getS3AccountOwner will result in signing a request and sending it to AWS, and getting a failure if your access key / secret key aren't correct. Unfortunately, this takes 200-300 ms.

我找到了一种使用以下代码在60毫秒内在Azure中完成此操作的方法:

I've found a way to accomplish this in Azure in 60 ms using the code below:

            final CloudBlobContainer container =
                    m_client.getContainerReference( UUID.randomUUID().toString() );
            container.exists();

上面的S3等效项无法满足我的目的(或者至少我无法弄清楚如何将其用于目的).任何人都对如何减少我发现的方法在200-300毫秒内确定授权是否正确的时间有任何想法?

The equivalent of the above for S3 doesn't work for my purpose (or at least I've not been able to figure out how to use it for my purpose). Anybody have any ideas as to how I can cut down on the time to determine if the authorization is correct from 200-300 ms with the approach I found?

推荐答案

类似的检查在AWS中不提供任何值.访问密钥和秘密密钥可以匹配,但是可能没有任何IAM策略,或者该策略可能仅限于IAM用户.因此,仅因为密钥有效并不意味着您就可以列出存储桶或使用这些凭据下载文件.

A check like that does not provide any value in AWS. An access key and a secret key may match but there may not be any IAM policies or the policies may be limited for the IAM user. So just because the keys are valid doesn't mean you'll be able to list buckets or download a file with those credentials.

您应该检查S3操作的结果,以确定权限是否不足以执行该操作,并在那时采取相应措施.

You should check the result of the S3 operation to determine if the permissions were insufficient for the operation and act accordingly at that time.

这篇关于使用AWS S3 Java SDK,确定授权(访问密钥和秘密密钥)是否正确的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆