0

I am getting the below error when i run the below program

public class IndexDocument {

    private static final String host = "search-mythird-sp3y4ptm4wutec5ijq5e4cpqae.eu-north-
    private static Region region = Region.EU_NORTH_1;

    static {
        System.setProperty("aws.accessKeyId", "AKIA3RYLN2OQT3K32G5B");
        System.setProperty("aws.secretKey", "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");
    }
    public static void main(String[] args) throws IOException, InterruptedException {
        
        SdkHttpClient httpClient = ApacheHttpClient.builder().build();
        try {

            //System.setProperty("aws.accessKeyId","admin");
            //System.setProperty("aws.secretKey","P@ssw0rd");
            
            OpenSearchClient client = new OpenSearchClient(
                    new AwsSdk2Transport(
                            httpClient,
                            host,
                            region,
                            AwsSdk2TransportOptions.builder().build()));

            // create the index
            String index = "sample-index";
            
            CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(index).build();
            client.indices().create(createIndexRequest);

            // index data
            Map<String, Object> document = new HashMap<>();
            document.put("firstName", "Michael");
            document.put("lastName", "Douglas");
            IndexRequest documentIndexRequest = new IndexRequest.Builder()
                    .index(index)
                    .id("2")
                    .document(document)
                    .build();
            client.index(documentIndexRequest);

            // delete the index
           // DeleteIndexRequest deleteRequest = new DeleteIndexRequest.Builder().index(index).build();
            //client.indices().delete(deleteRequest);
            
        } finally {
            httpClient.close();
        }
    }
}

..........

Exception in thread "main" org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [security_exception] authentication/authorization failure
    at org.opensearch.client.transport.aws.AwsSdk2Transport.parseResponse(AwsSdk2Transport.java:444)
    at org.opensearch.client.transport.aws.AwsSdk2Transport.executeSync(AwsSdk2Transport.java:365)
    at org.opensearch.client.transport.aws.AwsSdk2Transport.performRequest(AwsSdk2Transport.java:171)
    at org.opensearch.client.opensearch.indices.OpenSearchIndicesClient.create(OpenSearchIndicesClient.java:248)
    at org.IndexDocument.main(IndexDocument.java:46)

I tried to debug the code i found it is 403 forbidden error. I want to know how to solve this issue

toyota Supra
  • 3,181
  • 4
  • 15
  • 19

0 Answers0