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 = "AKIAZI2LI7EJNUUMDP4B";
String secretKey = "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";
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);
}
}
我正在尝试连接到 aws kendra 并使用以下代码行。 我收到以下错误:
我们计算的请求签名与您提供的签名不匹配。检查您的 AWS 秘密访问密钥和签名方法。有关详细信息,请参阅服务文档。 (服务:Kendra,状态代码:400,请求 ID:06ce1fc5-e040-4939-9a85-3e9b245f7a2e)
您遇到的异常表明您签署请求的方式存在问题。确保您使用的访问密钥和秘密密钥有效,并且具有访问 Kendra 服务的适当权限。仔细检查您使用的值是否正确,因为即使是很小的拼写错误也可能导致签名不正确。 (希望这不是你真正的钥匙)。