简体   繁体   English

如何解决 AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: null) 使用 java

[英]How to resolve AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: null) using java

Stack trace堆栈跟踪

Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: null), S3 Extended Request ID: null
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1182)
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:770)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:489)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:310)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3604)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3557)
    at com.amazonaws.services.s3.AmazonS3Client.getS3AccountOwner(AmazonS3Client.java:689)
    at com.amazonaws.services.s3.AmazonS3Client.getS3AccountOwner(AmazonS3Client.java:681)
    at testKMSkeyUploadObject.main(testKMSkeyUploadObject.java:101)

I am getting this exception when I am storing object in AmazonS3EncryptionClient object.当我在 AmazonS3EncryptionClient 对象中存储对象时出现此异常。 Here is my code这是我的代码

ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(plaintext.length);
                objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); 

    AmazonS3EncryptionClient s3 = new AmazonS3EncryptionClient(credentials,materialProvider).withRegion(Region.getRegion(Regions.US_EAST_1));;

    PutObjectRequest putRequest = new PutObjectRequest(
                        bucket, keyId, new ByteArrayInputStream(plaintext), objectMetadata);
    putRequest.setRequestCredentials(credentials);

    s3.setEndpoint("https://kms.us-east-1.amazonaws.com");

I have the same issue, but in my case the problem was with the proxy, Hhere is how you can set the proxy,我有同样的问题,但就我而言,问题出在代理上,这是设置代理的方法,

here is an example,这是一个例子,

ClientConfiguration config = new ClientConfiguration();
config.setProtocol(Protocol.HTTPS);
config.setProxyHost("YOUR_PROXY_IP");
config.setProxyPort(YOUR_PROXY_PORT);


BasicAWSCredentials creds = new BasicAWSCredentials("YOUR_KEY", "YOUR_SECRET"); 
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
    .withClientConfiguration(config)
    .withRegion(Regions.US_EAST_2)
    .withCredentials(new AWSStaticCredentialsProvider(creds))                   
    .build();

我通过在 Amazon IAM 管理控制台中创建存储桶并为端点获取主机解决了此异常。

I had the same issue and was caused by the usage of proxy because the application was living in the same region as the S3 bucket.我遇到了同样的问题,这是由使用代理引起的,因为应用程序与 S3 存储桶位于同一区域。 For the applications that were deployed in a different region the same code worked fine.对于部署在不同地区的应用程序,相同的代码工作正常。

I needed to be able to check whether the application is at the same region before setting the proxy client configuration.在设置代理客户端配置之前,我需要能够检查应用程序是否在同一区域。

暂无
暂无

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

相关问题 com.amazonaws.services.s3.model.AmazonS3Exception:Forbidden(Service:Amazon S3; Status Code:403; Error Code:403 Forbidden; Request ID:XXXXXXXX) - com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: XXXXXXXX) 访问被拒绝(服务:Amazon S3;状态代码:403;错误代码:AccessDenied;请求 ID:xxxxxxxxxxxxx) - Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: xxxxxxxxxxxxx) AWS S3 Java 拒绝访问服务:Amazon S3; 状态码:403; 错误代码:拒绝访问; - AWS S3 Java Access Denied Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Java Rest Service通过禁止403错误 - java rest service through forbidden 403 error Java SSL错误403禁止 - Java SSL error 403 Forbidden AWS S3 Java:d​​osObjectExist结果为403:禁止 - AWS S3 Java: doesObjectExist results in 403: FORBIDDEN maven tomcat7:deploy失败,状态码为:403,ReasonPhrase:Forbidden - maven tomcat7:deploy fails with status code:403, ReasonPhrase:Forbidden 如何尝试从Java客户端使用Sharepoint的Rest API,但获取状态码403禁止 - HowTrying to consume Rest api of Sharepoint from java client but getting status code 403 Forbidden 出现意外错误(类型=禁止,状态=403)。禁止 - There was an unexpected error (type=Forbidden, status=403).Forbiden “状态”:403,“错误”:“禁止”“消息”:邮递员弹簧启动代码中的“访问被拒绝” - "status": 403, "error": "Forbidden" "message": "Access Denied" in postman spring boot code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM