我正在使用 aws-java-sdk-1.12.457.jar
我在执行 AmazonHttpClient 时得到状态码 404,但是当我使用邮递员时我得到状态码 403
这是我的代码
AWSCredentialsProvider credentialsProvider = new InstanceProfileCredentialsProvider(false);
// Create AWSSecurityTokenService credentials
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(credentialsProvider)
.withRegion(REGION).build();
// Create credentials
AssumeRoleRequest roleRequest = new AssumeRoleRequest().withRoleArn(this.roleArn)
.withRoleSessionName(this.roleSessionName);
AssumeRoleResult roleResponse = stsClient.assumeRole(roleRequest);
Credentials sessionCredentials = roleResponse.getCredentials();
BasicSessionCredentials credentials = new BasicSessionCredentials(
sessionCredentials.getAccessKeyId(),
sessionCredentials.getSecretAccessKey(),
sessionCredentials.getSessionToken());
// Create request
DefaultRequest<Void> request = new DefaultRequest<Void>(SERVICE_NAME);
URI endpoint = new URI("https://domain/path/...");
request.setEndpoint(endpoint);
request.setHttpMethod(HttpMethodName.POST);
request.addHeader("content-type", "application/json");
request.setParameters(this.buildRequestParameter());
// sign AWS4Signer for request
AWS4Signer signer = new AWS4Signer();
signer.setServiceName(SERVICE_NAME);
signer.setRegionName(REGION);
signer.sign(request, credentials);
// Send request
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeout(10000);
AmazonHttpClient httpClient = AmazonHttpClient.builder().clientConfiguration(clientConfiguration).build();
RequestExecutionBuilder requestExecutionBuilder = httpClient.requestExecutionBuilder();
requestExecutionBuilder = requestExecutionBuilder.request(request);
requestExecutionBuilder.errorResponseHandler(new ErrorResponseHandler());
Response<Void> response = requestExecutionBuilder.execute();
return this.buildResponse(response);
我认为即使 aws author 失败了,我也应该获得状态 403 而不是 404