简体   繁体   English

AWS SDK 抛出 SdkClientException

[英]AWS SDK is throwing SdkClientException

I am attempting to retrieve a secret from aws secrets manager.我正在尝试从 aws secrets manager 中检索一个秘密。 My application can retrieve 3 / 4 secrets.我的应用程序可以检索 3 / 4 个秘密。 When attempting to retrieve the 2nd secret, i get an interrupt exception.当试图检索第二个秘密时,我得到一个中断异常。 The code below is what i am using.下面的代码是我正在使用的。 I am unsure where to look or why this is happening.我不确定在哪里寻找或为什么会发生这种情况。 It consistently happens when attempting to retrieve the 2nd secret.尝试检索第二个秘密时始终会发生这种情况。 I have verified that it exists in aws and that it contains the value i expect.我已经验证它存在于 aws 中并且它包含我期望的值。

I am using the reativerse [https://github.com/reactiverse/aws-sdk] library in tandem with vert.x + aws sdk 2. Any help or pointers on where to look would be greatly appreciated.我将 reativerse [https://github.com/reactiverse/aws-sdk] 库与 vert.x + aws sdk 2 结合使用。任何有关查看位置的帮助或指示将不胜感激。 The exception i see and the code i have are written below.我看到的异常和我的代码写在下面。

java.util.concurrent.ExecutionException: software.amazon.awssdk.core.exception.SdkClientException
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
    at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
    at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
    at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
    at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:829)
    Caused by: software.amazon.awssdk.core.exception.SdkClientException
    at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:98)
    at software.amazon.awssdk.core.internal.http.AmazonAsyncHttpClient$RequestExecutionBuilderImpl.execute(AmazonAsyncHttpClient.java:189)
    at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.invoke(BaseAsyncClientHandler.java:271)
    at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.doExecute(BaseAsyncClientHandler.java:213)
    at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.lambda$execute$1(BaseAsyncClientHandler.java:91)
    at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.measureApiCallSuccess(BaseAsyncClientHandler.java:277)
    at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.execute(BaseAsyncClientHandler.java:74)
    at software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler.execute(AwsAsyncClientHandler.java:52)
at software.amazon.awssdk.services.secretsmanager.DefaultSecretsManagerAsyncClient.getSecretValue(DefaultSecretsManagerAsyncClient.java:1142)
... 8 more
Caused by: software.amazon.awssdk.core.exception.SdkInterruptedException
at software.amazon.awssdk.core.internal.http.InterruptMonitor.checkInterrupted(InterruptMonitor.java:40)
at software.amazon.awssdk.core.internal.http.pipeline.stages.ApplyTransactionIdStage.execute(ApplyTransactionIdStage.java:43)
at software.amazon.awssdk.core.internal.http.pipeline.stages.ApplyTransactionIdStage.execute(ApplyTransactionIdStage.java:29)
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.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.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.AmazonAsyncHttpClient$RequestExecutionBuilderImpl.execute(AmazonAsyncHttpClient.java:185)
... 16 more
private final SecretsManagerAsyncClient client = VertxSdkClient.withVertx(SecretsManagerAsyncClient.builder(), ctx).build();
public <T> Promise<T> getSecret(String secretName) {
    Promise<T> completableFuture = Promise.promise();

    Context ctx = Vertx.vertx().getOrCreateContext();

    ctx.owner().executeBlocking(blockingFuture -> {
        try {
            GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
            CompletableFuture<GetSecretValueResponse> valueResponse = this.client.getSecretValue(valueRequest);

            GetSecretValueResponse getResponse = valueResponse.get();
            String response = getResponse.secretString();
            completableFuture.complete((T) Json.decodeValue(response, new <T>Object().getClass()));
            blockingFuture.complete();

        } catch (Exception e) {
            // log exception.
        }
    });

    ...
}

See SdkInterruptedException ...it has one method getResponse() :请参阅SdkInterruptedException ...它有一种方法getResponse()

try {

    // provoke the exception in here

} catch (SdkInterruptedException e) {
    System.err.println(e.getResponse());
}

This should (hopefully) at least tell why the request had been interrupted.这应该(希望)至少说明请求被中断的原因。
// log exception. is not the correct approach to handle any Exception .不是处理任何Exception的正确方法。

The SdkClientException might be more relevant than the SdkInterruptedException : SdkClientException可能比SdkInterruptedException更相关:

try { ...
} catch (SdkClientException e) {
    // log that exception, instead of ignoring it.
    System.err.println(e.getMessage());
}

This is how an Authorization Header (AWS Signature Version 4) should basically look alike. 就是授权标头(AWS 签名版本 4)的基本外观。 It may well be, that HMAC-SHA256 headers are being enforced (they're different on each single request).很可能,HMAC-SHA256 标头正在被强制执行(它们在每个请求中都不同)。 I could even provide a known to be working example ... which would show how to configure the SecretsManagerClient .我什至可以提供一个已知的工作示例......它将展示如何配置SecretsManagerClient I'd suspect the root cause related to that client's configuration.我怀疑与该客户端配置相关的根本原因。

When I read "when attempting to retrieve the 2nd secret", this with high probability means that you need a refresh the HMAC-SHA256 signature before the second request will be performed.当我阅读“尝试检索第二个秘密时”时,这很可能意味着您需要在执行第二个请求之前刷新 HMAC-SHA256 签名。 Destroying the client and constructing it again may be one sloppy workaround.销毁客户端并再次构建它可能是一种草率的解决方法。 When seeing duplicate values for AWS4-HMAC-SHA256 header on both requests, this definitely is the cause.当在两个请求上看到AWS4-HMAC-SHA256标头的重复值时,这绝对是原因。

我也有同样的问题,谁能告诉我为什么

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM