aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
6k stars 1.21k forks source link

Issue with Amazon CognitoSync + dates #373

Closed ricardclau closed 9 years ago

ricardclau commented 9 years ago

Hi

I am testing the Amazon CognitoSync API and I am getting the following error with the updateRecords method:

Fatal error: Uncaught Aws\CognitoSync\Exception\CognitoSyncException: AWS Error Code: SerializationException, Status Code: 400, AWS Request ID: 4856729f-5845-11e4-95fa-c931d79f176b, AWS Error Type: client, AWS Error Message: class java.lang.String can not be converted to milliseconds since epoch, User-Agent: aws-sdk-php2/2.7.1 Guzzle/3.9.2 curl/7.30.0 PHP/5.6.2

I am adding the Request ID in case that helps...

The failing call is:

$result = $clientSync->updateRecords([
    'IdentityPoolId' => $identityPoolId,
    'IdentityId' => $cognitoId,
    'DatasetName' => 'test',
    'RecordPatches' => array(
        array(
            'Op' => 'replace',
            'Key' => 'keytest',
            'Value' => 'valuetest' . time(),
            'SyncCount' => 0,
            'DeviceLastModifiedDate' => (new \DateTime())->getTimestamp(),
        ),
    ),
    'SyncSessionToken' => $syncToken,
]);

Both $identityPoolId and $cognitoId are valid (they actually work in other calls) and $syncToken has been obtained with

$syncToken = $clientSync->listRecords([
    'IdentityPoolId' => $identityPoolId,
    'IdentityId' => $cognitoId,
    'DatasetName' => 'test',
])->get('SyncSessionToken');

Any ideas on what can be wrong?

Best

jeremeamia commented 9 years ago

This might be a bug in how the SDK is sending the date values for this service.

  1. Can you provide a wire log of the request just so we can some clarification on what is going on.
  2. You might be able to patch it by putting a timestampFormat line, like in the SWF service description, into the Cognito Sync service description. Let me know if that works.
ricardclau commented 9 years ago

Hi @jeremeamia thanks for replying back this fast

Wire Log for the updateRecords call:

# Request:
POST /identitypools/us-east-1%3A87469e67-9916-44d2-9514-5049c6e81e17/identities/us-east-1%3Aa5dfeaec-6263-4074-a456-4f49125c7365/datasets/test HTTP/1.1
Host: cognito-sync.us-east-1.amazonaws.com
User-Agent: aws-sdk-php2/2.7.1 Guzzle/3.9.2 curl/7.30.0 PHP/5.6.2
Content-Type: application/json
x-amz-date: 20141020T162530Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIHL7XESDCUX3X5GQ/20141020/us-east-1/cognito-sync/aws4_request, SignedHeaders=host;x-amz-date, Signature=ed5e54150b4000279762622808a86c88a6493b4c02930d48739fe4e1049be30b
Content-Length: 491

{"RecordPatches":[{"Op":"replace","Key":"keytest","Value":"valuetest1413822330","SyncCount":0,"DeviceLastModifiedDate":"2014-10-20T16:25:30Z"}],"SyncSessionToken":"H4sIAAAAAAAAAB3OUW+CMBiF4b\/UumGCyS4YhQorXyMUanunQialncbBBv31w92\/58npltzrI\/iTDKdKHnre5z2Y6FebCEGFMCcXzEQya3EYOUmtqtACogg0aZ0Wn1j5rGdxbrv9+\/3iUvR0MnObgSSek2wBU8xg6te1uWvaTC21qKvtsDZ9eyxGLVPfxmjmLsGaaqtkY5hQz90IJHqBGF+B1BsmSgdkmAvTGPDFBqrsO3PltaXp+r\/kSmL7b9Jm9fJwh3eM07P4kW455eIrqPedmbrt7ACn20d5W6ag+lBsfNghjN7+AIf0bpsHAQAA"}

# Response:
HTTP/1.1 400 Bad Request
x-amzn-RequestId: b61a91dc-5875-11e4-8903-bd7a59eefce4
x-amzn-ErrorType: SerializationException:http://internal.amazon.com/coral/com.amazon.coral.service/
Content-Type: application/json
Content-Length: 85
Date: Mon, 20 Oct 2014 16:25:31 GMT
nnCoection: close

{"Message":"class java.lang.String can not be converted to milliseconds since epoch"}

So, DeviceLastModifiedDate is in ISO8601 format which I assume is created by either the SDK or Guzzle itself?

I have also tried approach 2, but the timestamp is still serialized in ISO8601 format although I have changed cognitoSync-2014-06-30.php, am I missing something?

Please let me know if this is enough or I can help with some extra logs

ricardclau commented 9 years ago

Hi @jeremeamia the date formatting problem has disappeared in 2.7.2 (I patched wrongly cognitoSync-2014-06-30.php in my local code) but I am getting now a 403 credentials problem.

In the API it does not say the ClientContext is mandatory and AFAIK I am supplying all needed fields. Everything else I have tried seems to work which makes me think there is another bug here.

I am providing the logs in case they are helpful

# Request:
POST /identitypools/us-east-1%3A87469e67-9916-44d2-9514-5049c6e81e17/identities/us-east-1%3Aa5dfeaec-6263-4074-a456-4f49125c7365/datasets/test HTTP/1.1
Host: cognito-sync.us-east-1.amazonaws.com
User-Agent: aws-sdk-php2/2.7.2 Guzzle/3.9.2 curl/7.30.0 PHP/5.6.2
Content-Type: application/json
x-amz-date: 20141024T103450Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIHL7XESDCUX3X5GQ/20141024/us-east-1/cognito-sync/aws4_request, SignedHeaders=host;x-amz-date, Signature=1a1327177c46dcba95fdecd6258633f9cfa90f951e903e026fe37f397cb54481
Content-Length: 483

{"RecordPatches":[{"Op":"replace","Key":"keytest","Value":"valuetest1414146890","SyncCount":0,"DeviceLastModifiedDate":1414146890}],"SyncSessionToken":"H4sIAAAAAAAAAB3O3U6DMBiA4QvagS3Mny3xYFLoyuhHYIXSnpnBQgsoiaDQqxc9f\/PkbdbY6QrcuzzMV5mZ1DCP27xTNhq4QVhZ9ZiIcNEim5SMWzC416Q0mnRO22wPhJkkiPvm\/Dbehgj9Ocx+LkBCxEXmc9H9gFP+1oyalnNNe9QUfbc1pq74pGXk6gAt6RBiTXWvZGkToVawfAJy8iHALZDCS0Q+AOkWbksLjntwZV9syNuaRtt\/niqJ+3+TlpsXH474eM9fHhhV+\/NuvNfT+uzSG3qa6cXt\/O8L58UpCCo7zuiDoNdfLMwmWAcBAAA="}
# Response:
HTTP/1.1 403 Forbidden
x-amzn-RequestId: 6272023c-5b69-11e4-a087-954ee4c655e2
x-amzn-ErrorType: NotAuthorizedException:http://cognito-sync.amazonaws.com/doc/2014-06-30/
Content-Type: application/json
Content-Length: 73
Date: Fri, 24 Oct 2014 10:34:50 GMT

{"message":"These credentials are not valid for accessing this resource"}