我使用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服务的管理员权限,因此我不确定是什么问题。
感谢任何帮助。
答案 0 :(得分:1)
问题已经为API输入了错误的apiKey
。
当我将其更改为由API Gateway生成的有效API密钥时,一切正常。
此外,您必须确保API密钥链接到有效的使用计划,否则它将无效
答案 1 :(得分:0)
通常类更像:
decode('UTF-8')
也许你的lambda不能开始