# AWS OpenSearch Service. Request failed: \[security\_exception\] authentication/authorization failure

**URL:** <https://forum.opensearch.org/t/aws-opensearch-service-request-failed-security-exception-authentication-authorization-failure/13682>\
**Category:** Security\
**Tags:** troubleshoot, security-issue\
**Created:** [March 29, 2023, 12:39pm UTC](https://forum.opensearch.org/t/aws-opensearch-service-request-failed-security-exception-authentication-authorization-failure/13682 "2023-03-29T12:39:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarasvovk](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/tarasvovk/32/5234_2.png) [@tarasvovk](https://forum.opensearch.org/u/tarasvovk)\
**Post date:** [March 29, 2023, 12:39pm UTC](https://forum.opensearch.org/t/aws-opensearch-service-request-failed-security-exception-authentication-authorization-failure/13682/1 "2023-03-29T12:39:27Z")

</div>

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:

```auto
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:

```auto
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

 ![pic_1](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/e/e93771dcf08b97d8650fb67f6ae0fd7b2e4fbbff.png)

---

<div class="post-metadata">

**Author:** ![gaobinlong](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gaobinlong/32/5242_2.png) [@gaobinlong](https://forum.opensearch.org/u/gaobinlong)\
**Post date:** [June 5, 2023, 8:44am UTC](https://forum.opensearch.org/t/aws-opensearch-service-request-failed-security-exception-authentication-authorization-failure/13682/2 "2023-06-05T08:44:21Z")

</div>

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