Java com.amazonaws.services.s3.model.AmazonS3Exception:禁止(服务:Amazon S3;状态代码:403;错误代码:403 禁止;请求 ID:XXXXXXXX)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33218538/
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
com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: XXXXXXXX)
提问by Shashank.gupta40
From few days back i am receiving this exception when i try to push files to my S3Bucket. Ealier everything seems to work and i am sure there is no code changes from my side.
几天前,当我尝试将文件推送到我的 S3Bucket 时,我收到了这个异常。Ealier 似乎一切正常,我确信我这边没有代码更改。
com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden
(Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden;
Request ID: XXXXXXXXXXXX),
S3 Extended Request ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1077)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:725)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:460)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:295)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3699)
at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:999)
at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:977)
.... ....
…………
I came across many such Q related to com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden following those
我遇到了许多与 com.amazonaws.services.s3.model.AmazonS3Exception 相关的 Q:禁止遵循这些
- I have installed NTP on my server to solve any time related issue.
- I have also added endPointUrl for "AmazonS3Client" object to the code which i feel may solve my problem.
- 我已经在我的服务器上安装了 NTP 来解决任何与时间相关的问题。
- 我还为“AmazonS3Client”对象添加了 endPointUrl 到我认为可以解决我的问题的代码中。
Anything else i can try to solve this issue
还有什么我可以尝试解决这个问题
i am using aws-java-sdk:1.9.10 for pushing files to S3 Bucket.
我正在使用 aws-java-sdk:1.9.10 将文件推送到 S3 Bucket。
回答by gregwhitaker
Most likely your instance has not been launched with an IAM instance profile role that has access to S3.
很可能您的实例尚未使用有权访问 S3 的 IAM 实例配置文件角色启动。
All access to AWS services must be signed with access key and secret. When you do this from your local machine the DefaultCredentialsProviderChain
uses the access key and secret defined in your .aws/credentials
file.
所有对 AWS 服务的访问都必须使用访问密钥和秘密进行签名。当您从本地计算机执行此操作时,将DefaultCredentialsProviderChain
使用.aws/credentials
文件中定义的访问密钥和机密。
When you launch an EC2 instance in AWS it also needs to sign the requests to services, like s3. However, it does this by retrieving it's credentials from an internal metadata service.
当您在 AWS 中启动 EC2 实例时,它还需要签署对服务(如 s3)的请求。但是,它是通过从内部元数据服务检索其凭据来实现的。
So what you do is create an IAM instance profile that your instance will assume when it starts up. This IAM instance profile, like other IAM profiles for user's for example, defines what the instance has access to.
因此,您要做的是创建一个 IAM 实例配置文件,您的实例在启动时将采用该配置文件。此 IAM 实例配置文件与用户的其他 IAM 配置文件一样,定义了实例有权访问的内容。
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
回答by kdblue
In my case bucket name was different at android side ( bucket name was 'a' at S3 and i entered 'ab' at android side), by changing bucket name and vice versa, I solved issue.
在我的情况下,存储桶名称在 android 端是不同的(存储桶名称在 S3 是“a”,我在 android 端输入了“ab”),通过更改存储桶名称,反之亦然,我解决了问题。