AWS api using casablanca

Jul 27, 2015 at 11:06 PM
Hello everybody, I'm trying to use casablanca to create the request to the Amazon DynamoDB.
But request needs a signature of "canonical request" (smth like "POST / \nheaders, etc...")
My signature differs from Amazon's made one.
The request is successful if I use libcurl, so my signature is completely correct.

Output of casablanca's request is:
POST https://dynamodb.eu-central-1.amazonaws.com/ HTTP/1.1
Accept: /
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIDMXLOUBKV75N4LA/20150727/eu-central-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=e5fa7b77af7824649287e06b6cb003f98d8bdd370983a2479153642d827a7e68
Content-Length: 111
Content-Type: application/json
Host: dynamodb.eu-central-1.amazonaws.com
X-Amz-Date: 20150727T212824Z
X-Amz-Target: DynamoDB_20120810.GetItem


output of libcurl request is:
POST / HTTP/1.1
Host: dynamodb.eu-central-1.amazonaws.com
Accept: /
Content-Type:application/json
X-Amz-Date:20150727T212824Z
X-Amz-Target:DynamoDB_20120810.GetItem
Authorization:AWS4-HMAC-SHA256 Credential=AKIAIDMXLOUBKV75N4LA/20150727/eu-central-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=e5fa7b77af7824649287e06b6cb003f98d8bdd370983a2479153642d827a7e68
Content-Length: 111


Can anybody tell me, does casablanca really inserts dull endpoint after "POST" while requesting?
Or may be anybody have other ideas why this request is incorrect?
Coordinator
Jul 28, 2015 at 12:47 AM
Hi Nemanicka,

Could you please include the code you're using to generate this request (especially the section with the url_builder)?
Jul 28, 2015 at 7:13 PM
Sure, the basic logic of creating request is:
    string endpoint = "https://dynamodb.eu-central-1.amazonaws.com";

    http_request req(methods::POST);
    req.set_request_uri(endpoint.c_str());
    req.headers().clear();
    req.headers().add("Authorization", authorization_header.c_str());
    req.headers().add("X-Amz-Date", amz_date.c_str());
    req.headers().add("X-Amz-Target", amz_target.c_str());
    req.headers().add("Content-Type", content_type.c_str());
    req.headers().add("Accept", "*/*");
    req.headers().add("Host","dynamodb.eu-central-1.amazonaws.

    req.set_body(request_parameters.c_str());
    
   client::http_client client(endpoint);

    string reqstr = req.to_string();

    /* The request in previous post is printed by this line */ 
    cout << reqstr << "\nend"<< endl;

    client.request(req).then([](pplx::task<web::http::http_response> task)
     {
       web::http::http_response response = task.get();
       cout << "response = " <<  response.to_string() << endl;
     });
Actually, I've tried to set endpoint as empty relative URL ( "/" ), I found in sources that it's possible, but
in this case I've got an exception "invalied endpoint".
Coordinator
Jul 28, 2015 at 8:37 PM
I believe the issue is that you're using endpoint both as the server to connect to, as well as the path within the server to connect to. Try changing the line
req.set_request_uri(endpoint.c_str());
to be
req.set_request_uri(U("/"));
Marked as answer by roschuma on 7/28/2015 at 1:30 PM
Jul 28, 2015 at 9:29 PM
Thank you, it particularly works, because relative URL now is "/" (previously I've tried to set this URL for client, which is wrong), but I still have wrong request.
Anyway, my issue is completely resolved, thank you for the answer!