Я пытаюсь использовать AWS S3AsyncClient для получения / чтения файла из хранилища объектов. Мое конечное намерение состоит в том, чтобы использовать это в моем проекте Vert.x, но перед использованием с Vert.x я хотел, чтобы он работал автономно. Следуя нескольким форумам, я написал код ниже, но он выдает ошибку «software.amazon.awssdk.core.exception.SdkClientException: учетные данные не должны быть нулевыми.». Хотя я предоставляю здесь учетные данные, он говорит, что не получает их. Может кто-нибудь помочь мне здесь?
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
public class S3AsyncStreamOps {
public static void main(String[] args) {
AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create("my_access_key", "my_secret_key"));
S3AsyncClient s3Client;
try {
s3Client = S3AsyncClient.builder().credentialsProvider(creds)
.region(Region.US_WEST_1)
.endpointOverride(new URI("https://someobjectstorage.server.com:9021"))
.build();
CompletableFuture<GetObjectResponse> futureGet = s3Client.getObject(
GetObjectRequest.builder()
.bucket("my_bucket_name")
.key("/somepath/anotherpath/myData.pdf")
.build(),
AsyncResponseTransformer.toFile(Paths.get("/osfile/myfile.pdf")));
futureGet.get();
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
С приведенным выше кодом я получаю трассировку стека исключений как:
java.util.concurrent.ExecutionException: software.amazon.awssdk.core.exception.SdkClientException: Credentials must not be null.
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
at com.aexp.ecp.vertx.spring.verticles.S3AsyncStreamOps.main(S3AsyncStreamOps.java:54)
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Credentials must not be null.
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:97)
at software.amazon.awssdk.core.internal.util.ThrowableUtils.asSdkException(ThrowableUtils.java:98)
at software.amazon.awssdk.core.internal.http.AmazonAsyncHttpClient$RequestExecutionBuilderImpl.execute(AmazonAsyncHttpClient.java:193)
at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.invoke(BaseAsyncClientHandler.java:263)
at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.doExecute(BaseAsyncClientHandler.java:205)
at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.execute(BaseAsyncClientHandler.java:134)
at software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler.execute(AwsAsyncClientHandler.java:58)
at software.amazon.awssdk.services.s3.DefaultS3AsyncClient.getObject(DefaultS3AsyncClient.java:3949)
at com.aexp.ecp.vertx.spring.verticles.S3AsyncStreamOps.main(S3AsyncStreamOps.java:32)
Caused by: java.lang.NullPointerException: Credentials must not be null.
at software.amazon.awssdk.utils.Validate.paramNotNull(Validate.java:117)
at software.amazon.awssdk.auth.signer.params.Aws4SignerParams.<init>(Aws4SignerParams.java:42)
at software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams.<init>(AwsS3V4SignerParams.java:27)
at software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams.<init>(AwsS3V4SignerParams.java:21)
at software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams$BuilderImpl.build(AwsS3V4SignerParams.java:121)
at software.amazon.awssdk.auth.signer.AwsS3V4Signer.constructAwsS3SignerParams(AwsS3V4Signer.java:93)
at software.amazon.awssdk.auth.signer.AwsS3V4Signer.sign(AwsS3V4Signer.java:59)
at software.amazon.awssdk.core.internal.http.pipeline.stages.SigningStage.signRequest(SigningStage.java:63)
at software.amazon.awssdk.core.internal.http.pipeline.stages.SigningStage.execute(SigningStage.java:49)
at software.amazon.awssdk.core.internal.http.pipeline.stages.SigningStage.execute(SigningStage.java:35)
at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)
at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryExecutor.doExecute(AsyncRetryableStage.java:208)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryExecutor.execute(AsyncRetryableStage.java:107)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryExecutor.execute(AsyncRetryableStage.java:102)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage.execute(AsyncRetryableStage.java:78)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage.execute(AsyncRetryableStage.java:51)
at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)
at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncExecutionFailureExceptionReportingStage.execute(AsyncExecutionFailureExceptionReportingStage.java:41)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncExecutionFailureExceptionReportingStage.execute(AsyncExecutionFailureExceptionReportingStage.java:29)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallTimeoutTrackingStage.execute(AsyncApiCallTimeoutTrackingStage.java:64)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallTimeoutTrackingStage.execute(AsyncApiCallTimeoutTrackingStage.java:36)
at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)
at software.amazon.awssdk.core.internal.http.AmazonAsyncHttpClient$RequestExecutionBuilderImpl.execute(AmazonAsyncHttpClient.java:191)
... 6 more