gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:02:29 27 4
gpt4 key购买 nike

堆栈跟踪

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)

当我在 AmazonS3EncryptionClient 对象中存储对象时出现此异常。这是我的代码

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");

最佳答案

我有同样的问题,但在我的情况下,问题出在代理上,这里是如何设置代理,

这是一个例子,

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();

关于java - 如何解决 AmazonS3Exception : Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: null) using java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32328376/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com