java 您提供的 AWS 访问密钥 ID 在我们的记录中不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42112590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The AWS Access Key Id you provided does not exist in our records
提问by Ishan Tiwary
I had written a library in PHP using the AWS to communicate with the ECS server. Now I am migrating my code to java. In java I am using the same key and secret which I used in PHP.
我使用 AWS 用 PHP 编写了一个库来与 ECS 服务器进行通信。现在我正在将我的代码迁移到 java。在 Java 中,我使用的密钥和秘密与我在 PHP 中使用的相同。
In php I used the following method:
在 php 中,我使用了以下方法:
$s3 = Aws\S3\S3Client::factory(array( 'base_url' => $this->base_url, 'command.params' => array('PathStyle' => true), 'key' => $this->key, 'secret' => $this->secret ));
In java I am using following method
在java中我使用以下方法
BasicAWSCredentials(String accessKey, String secretKey);
I am getting the following exception:
我收到以下异常:
Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception: The AWS Access Key Id you provided does not exist in our records. (Service: Amazon S3; Status Code: 403; Error Code: InvalidAccessKeyId; Request ID: 3A3000708C8D7883), S3 Extended Request ID: U2rG9KLBBQrAqa6M2rZj65uhaHhOpZpY2VK1rXzqoGrKVd4R/JdR8aeih/skG4fIrecokE4FY3w=
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1401)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:945)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:723)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:475)
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:437)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:386)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3996)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3933)
at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:851)
at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:857)
at com.justdial.DocUpload.DocUpload.main(DocUpload.java:22)
Do I need a new key and secret for Java or the previous one can be used.
我需要一个新的 Java 密钥和秘密还是可以使用以前的密钥和秘密。
My questions are: 1 - Is then any prerequisite that we need to follow before using AWS's BasicAwsCredentials() method. 2 - Do we need to create the IAM roles. 3 - If we do then how will it come to know which IP to hit as in case of PHP in Aws\S3\S3Client::factory method I was specifying the base url.
我的问题是: 1 - 那么在使用 AWS 的 BasicAwsCredentials() 方法之前,我们是否需要遵循任何先决条件。2 - 我们是否需要创建 IAM 角色。3 - 如果我们这样做,那么它将如何知道要命中哪个 IP,就像我在 Aws\S3\S3Client::factory 方法中指定的基本 url 中的 PHP 一样。
采纳答案by Ishan Tiwary
Following code worked for me.
以下代码对我有用。
String accesskey = "objuser1";
String secret = "xxxxxxxxxxxxxxxx";
ClientConfiguration config = new ClientConfiguration();
config.setProtocol(Protocol.HTTP);
AmazonS3 s3 = new AmazonS3Client(new BasicAWSCredentials(accesskey, secret), config);
S3ClientOptions options = new S3ClientOptions();
options.setPathStyleAccess(true);
s3.setS3ClientOptions(options);
s3.setEndpoint("1.2.3.4:9020"); //ECS IP Address
System.out.println("Listing buckets");
for (Bucket bucket : s3.listBuckets()) {
System.out.println(" - " + bucket.getName());
}
System.out.println();
回答by Venkatesh
AWS access key and secret access keys are independent of SDKs you use (doesn't matter whether you use PHP, Java or Ruby etc), it's more about granting and getting access to services you run/use on AWS.
AWS 访问密钥和秘密访问密钥独立于您使用的开发工具包(无论您使用 PHP、Java 还是 Ruby 等),更多的是授予和获取您在 AWS 上运行/使用的服务的访问权限。
Root cause of the error is I think you've not set AWS region though you've given access key and secret access key. Please check thisto set AWS credentials for Java.
错误的根本原因是我认为您没有设置 AWS 区域,尽管您已经提供了访问密钥和秘密访问密钥。请选中此项以设置 Java 的 AWS 凭证。
To answer your questions.
回答你的问题。
As far as I know BasicAwsCredentials() itself acts as prerequisite step before you want to do anything with Amazon services. Only prerequisite for BasicAwsCredentials() is to have the authentication keys.
No, it's not mandatory step. It's an alternative. Please check the definition of IAM role from thislink.
You can use the 'endpoint' to do the same job in Java. Check 'endpoint' details from thislink.
据我所知,BasicAwsCredentials() 本身是您想对 Amazon 服务执行任何操作之前的先决步骤。BasicAwsCredentials() 的唯一先决条件是拥有身份验证密钥。
不,这不是强制性步骤。这是一个替代方案。请从检查IAM角色的定义此链接。
您可以使用“端点”在 Java 中完成相同的工作。检查“端点”从细节此链接。
Please take a look at the examples from here. Using the same method I'm able to successfully do the 'BasicAwsCredentials()'. And also cross check whether 'access key' and 'secret access key' have necessary permissions to access Amazon services as per your need. Check IAM user, group and ensure they've necessary AWS permissions.
请看看这里的例子。使用相同的方法,我能够成功执行“BasicAwsCredentials()”。并且还交叉检查“访问密钥”和“秘密访问密钥”是否具有根据您的需要访问亚马逊服务的必要权限。检查 IAM 用户、组并确保他们拥有必要的 AWS 权限。