skip to Main Content

import java.io.IOException;
import java.util.List;

import javax.servlet.Servlet;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.kendra.KendraClient;
import software.amazon.awssdk.services.kendra.model.AttributeFilter;
import software.amazon.awssdk.services.kendra.model.DocumentAttribute;
import software.amazon.awssdk.services.kendra.model.DocumentAttributeValue;
import software.amazon.awssdk.services.kendra.model.QueryRequest;
import software.amazon.awssdk.services.kendra.model.QueryResponse;




@Component(service = {Servlet.class},
property = {
    "sling.servlet.paths=/bin/cookieservlet"
    }
)

public class CookieServlet extends SlingAllMethodsServlet{

    Logger log = LoggerFactory.getLogger(CookieServlet.class);

    
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException{
       
        

        String accessKey = "AKIAYHKHKJHUMDP4B";
        String secretKey = "V9wWb3Hz6oGIUHUKHKDdfyiushdPsOOqzsbdYf/Zxse";
        String indexId = "6cc7a433-d9ea-4c68-9b06-76646d6a2529";

        AwsCredentials awsCredentials = AwsBasicCredentials.create(accessKey, secretKey);

        KendraClient kendraClient = KendraClient.builder()
                                            .region(Region.US_EAST_1)
                                            .credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
                                            .build();



                                            
      
        QueryRequest queryRequest = QueryRequest.builder()
                                        .queryText(searchWord)
                                        .indexId(indexId)
                                        .build();
       QueryResponse queryResult = kendraClient.query(queryRequest);
       if(queryRequest!=null){
        log.info("Query executed successfully",queryRequest);
       }

       response.getWriter().write(queryResult.toString());
       response.sendRedirect(targetPageUrl);

   }
}






 


I am trying to make a connection to aws kendra and used the following lines of code.
I am getting the following error :

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. (Service: Kendra, Status Code: 400, Request ID: 06ce1fc5-e040-4939-9a85-3e9b245f7a2e)

2

Answers


  1. The exception you’re encountering suggests that there’s an issue with the way you’re signing your requests. Ensure that the access key and secret key you’re using are valid and have the appropriate permissions to access the Kendra service. Double-check that you’re using the correct values, as even a small typo can cause the signature to be incorrect. (Hope this are not your real keys).

    Login or Signup to reply.
  2. Were you able to resolve this? I’m having same issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search