Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during sending a signed http request to ElasticSearch #188

Open
karannparikh opened this issue Aug 15, 2023 · 0 comments
Open

Error during sending a signed http request to ElasticSearch #188

karannparikh opened this issue Aug 15, 2023 · 0 comments

Comments

@karannparikh
Copy link

hey,
I am running into an error while making a httprequest to Elastic Search The error is

The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method

Following is the code. Any pointers to bug in my code or library would be appreciated.

`invocation_response my_handler(invocation_request const& request)
{
 ClientConfiguration config;
 config.region = Aws::Environment::GetEnv("AWS_REGION");
 config.caFile = "/etc/pki/tls/certs/ca-bundle.crt";
 auto credentialsProvider = Aws::MakeShared<Aws::Auth::EnvironmentAWSCredentialsProvider>("es");

 auto client = CreateHttpClient(config);
 auto httpRequest = CreateHttpRequest(URL, HttpMethod::HTTP_GET, 
Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);

 httpRequest->SetContentType("application/json");

 nlohmann::json query1 = {};
 query1.emplace("size", 25);

 std::shared_ptr<Aws::StringStream> sstream = make_shared<Aws::StringStream>();
 *sstream << query1;
 httpRequest->AddContentBody(sstream);
 Aws::Client::AWSAuthV4Signer signer(credentialsProvider, "es", config.region); 
 auto req =  httpRequest.get();
 signer.SignRequest(*req);
 auto outcome = client->MakeRequest(httpRequest);
 if (outcome->GetResponseCode() == HttpResponseCode::OK) {
    cout << "SUCCESS" << endl;
 } else {
    // print the response from the http request
    cout << "ERROR" << endl;
    cout << outcome->GetResponseBody().rdbuf() << endl;
    cout << outcome->GetResponseCode() << endl;

 }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant