daniele-salvagni / aws-sdk-esp8266

📜 A detached fork of aws-sdk-arduino adding support for the ESP8266 module.
Apache License 2.0
34 stars 13 forks source link

No Response Body from AWS #4

Open pherris opened 8 years ago

pherris commented 8 years ago

I am having an issue where the Esp8266DateTimeProvider is not being updated with the current time. Based on some review of the code, it seems like the first failure response from AWS should set the current time on the unit, but I am not seeing any response back from the POST at all.

I modified the AwsClient.cpp file to log some data:

char* AWSClient::sendData(const char* data) {
    char* server = new char[strlen(awsService) + strlen(awsRegion)
            + strlen(awsEndpoint) + 4]();
    sprintf(server, "%s.%s.%s", awsService, awsRegion, awsEndpoint);
    int port = httpS ? 443 : 80;
    Serial.println("data");
    Serial.println(data);
    Serial.println("server");
    Serial.println(server);
    Serial.println("port");
    Serial.println(port);
    char* response = httpClient->send(data, server, port);
    delete[] server;
    return response;
}

and the request I am sending looks like this:

data
POST http://dynamodb.us-east-1.amazonaws.com/ HTTP/1.1
content-length:109
content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
x-amz-date:20000101T000041Z
x-amz-target:DynamoDB_20120810.PutItem
Authorization: AWS4-HMAC-SHA256 Credential=AXXXXXXXXXQ/20000101/us-east-1/dynamodb/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target, Signature=bcXXXXXXXXXXX1833e0
Connection:close

{"Item":{"Device":{"S":"huzzah1"},"time":{"N":"20000101000041"},"temp":{"N":"21"}},"TableName":"TestTable"}
server
dynamodb.us-east-1.amazonaws.com
port
80

In AmazonDynamoDBClient.cpp I log the response:

    char* response = sendData(request);
    Serial.println(">>>>>>>>>>>>>");
    Serial.println(response);

and I get nothing back:

>>>>>>>>>>>>>

ERROR: Connection problem

However, when I use POSTMAN to make the same POST request, I do get the expected 400 response with a body:

{
  "__type": "com.amazon.coral.service#InvalidSignatureException",
  "message": "Signature expired: 20000101T000039Z is now earlier than 20160807T023046Z (20160807T024546Z - 15 min.)"
}

which seems like it could do the trick of updating the time. Any ideas for me?

PS - thanks for your work on this library - I wonder if it would be possible to merge in the work from https://github.com/svdgraaf/aws-sdk-arduino and https://github.com/canadaduane/aws-sdk-esp8266 eventually?

pherris commented 8 years ago

Ah, I see - you are expecting each implementation to pass this in on failure...