我在403 forbidden
尝试aws elasticsearch
通过 java Jest(v6.3) elasticsearch 客户端删除索引时遇到 http 错误(它将 http 调用委托给apache httpclient(v4.5.2) 我知道我的权限在 AWS 中设置正确,因为我是能够成功使用邮递员(在 AWS 签名授权助手的帮助下)。但是,apache httpclient
当我发出时,DELETE /{myIndexName}
我收到以下错误:
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.
我通过使用签署aws
请求apache httpclient
的拦截器配置来签署请求。(下面的代码用于Spring Framework @Configuration
连接javaJest
客户端和底层apache httpclient的类)但我想如果我直接使用apache httpclient我会体验到同样的问题。
@Configuration
public class ElasticSearchConfiguration {
@Autowired
private CredentialsProviderFactoryBean awsCredentialsProvider;
@Bean
public JestClient awsJestClient(@Value("${elasticsearch.url}") String connectionUrl) throws Exception {
com.amazonaws.auth.AWSCredentialsProvider provider = awsCredentialsProvider.getObject();
final com.google.common.base.Supplier<LocalDateTime> clock = () -> LocalDateTime.now(ZoneOffset.UTC);
final vc.inreach.aws.request.AWSSigner awsSigner = new vc.inreach.aws.request.AWSSigner(provider, "us-east-1", "es", clock);
final vc.inreach.aws.request.AWSSigningRequestInterceptor requestInterceptor = new vc.inreach.aws.request.AWSSigningRequestInterceptor(awsSigner);
final JestClientFactory factory = new JestClientFactory() {
@Override
protected HttpClientBuilder configureHttpClient(HttpClientBuilder builder) {
builder.addInterceptorLast(requestInterceptor);
return builder;
}
@Override
protected HttpAsyncClientBuilder configureHttpClient(HttpAsyncClientBuilder builder) {
builder.addInterceptorLast(requestInterceptor);
return builder;
}
};
factory.setHttpClientConfig(new HttpClientConfig
.Builder(connectionUrl)
.connTimeout(60000)
.multiThreaded(true)
.build());
return factory.getObject();
}
}
由于它与邮递员合作,因此它指出了签名错误,但我不知道差异发生在哪里。上面的配置适用于apache httpclient
除 http DELETE 请求之外的所有请求。