gpt4 book ai didi

java - AWS API Gateway 生成 SDK 请求错误

转载 作者:行者123 更新时间:2023-12-02 11:11:32 25 4
gpt4 key购买 nike

我已使用 AWS API Gateway 创建了一个 API。 API 中使用的所有方法都需要 IAM 身份验证。

我尝试在本地测试 API 并得到以下异常:

myapi.model.MyAPIException: The request signature we   calculated does not match the signature you provided. Check your AWS Secret  Access Key and signing method. Consult the service documentation for details.
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1632)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1304)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1058)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
at com.amazonaws.client.ClientHandlerImpl.doInvoke(ClientHandlerImpl.java:204)
at com.amazonaws.client.ClientHandlerImpl.invoke(ClientHandlerImpl.java:185)
at com.amazonaws.client.ClientHandlerImpl.execute(ClientHandlerImpl.java:93)
at com.amazonaws.opensdk.protect.client.SdkClientHandler.execute(SdkClientHandler.java:42)
at myapi.MyAPIClient.myMethod(MyAPIClient.java:101)
...

为了构建请求,我使用了以下代码:

public static void main(String[] args) {

MyAPI client = MyAPI .builder()
.apiKey(myApiKey)
.iamCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.build();

MyMethodRequest myMethodRequest = new MyMethodRequest().arg(methodArg);

MyMethodResult result = client.myMethod(myMethodRequest);
}

DefaultAWSCredentialsProviderChain 加载的凭证是我的凭证,它对我的​​所有 AWS 服务具有管理员访问权限,因此我不确定出了什么问题。

感谢任何帮助。

最佳答案

问题最终是因为为 API 输入了错误的 apiKey。当我将其更改为 API Gateway 生成的有效 API key 时,一切正常。

此外,您必须确保 API key 链接到有效的使用计划,否则它将不起作用

关于java - AWS API Gateway 生成 SDK 请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585623/

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