AWS OpenSearch Service. Request failed: [security_exception] authentication/authorization failure

I’m trying to use OpenSearch to connect to my OpenSearch domain on AWS. I set env for AWS. However, I’m encountering an authentication/authorization failure. Here’s my code:

public class Example {

  public static void main(final String[] args) throws IOException {
    SdkHttpClient httpClient = ApacheHttpClient.builder().build();
    try {
      OpenSearchClient client =
          new OpenSearchClient(
              new AwsSdk2Transport(
                  httpClient,
                  "search-*****-3ovub4o4gncugluu6t2tquptnu.eu-central-1.es.amazonaws.com",
                  Region.EU_CENTRAL_1,
                  AwsSdk2TransportOptions.builder().build()));

      InfoResponse info = client.info();
      System.out.println(info.version().distribution() + ": " + info.version().number());
    } finally {
      httpClient.close();
    }
  }
}

When I run this code, I get the following exception:

Exception in thread "main" org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [security_exception] authentication/authorization failureat org.opensearch.client.transport.aws.AwsSdk2Transport.parseResponse(AwsSdk2Transport.java:47)at org.opensearch.client.transport.aws.AwsSdk2Transport.executeSync(AwsSdk2Transport.java:393)at org.opensearch.client.transport.aws.AwsSdk2Transport.performRequest(AwsSdk2Transport.java:191)at org.opensearch.client.opensearch.OpenSearchClient.info(OpenSearchClient.java:790)at Example.main(Example.java:25)

I believe I have the correct permissions set up for my IAM user, and I’m using the correct access key and secret key. However, I still can’t seem to resolve this issue. What am I missing or doing wrong? Any help or guidance would be appreciated.

this is my aws config

Seems that the domain name in your IAM policy and the code are not consistent, you can check that.

1 Like