Error during sending a signed http request to ElasticSearch

Open
#188 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
aws, cpp, elasticsearch
Domain
api, cloud, security

Research direction

Start with the request construction and Aws::Client::AWSAuthV4Signer::SignRequest call shown in the issue, then reproduce the request against Elasticsearch using the configured region and environment credentials. Compare the signing inputs with the service response; done means confirming a library defect with a minimal reproduction or documenting a correction to the caller's setup.

Written by the indexing model from the issue text.

Description

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;

 }`

Dominant language
C++
Stars
465
Forks
98
Avg merge
1h 16m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from awslabs/aws-lambda-cpp

All issues in awslabs/aws-lambda-cpp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.