UpdateRecords - Amazon Cognito Sync

UpdateRecords

Posts updates to records and adds and deletes records for a dataset and user.

The sync count in the record patch is your last known sync count for that record. The server will reject an UpdateRecords request with a ResourceConflictException if you try to patch a record with a new value but a stale sync count.

For example, if the sync count on the server is 5 for a key called highScore and you try and submit a new highScore with sync count of 4, the request will be rejected. To obtain the current sync count for a record, call ListRecords. On a successful update of the record, the response returns the new sync count for that record. You should present that sync count the next time you try to update that same record. When the record does not exist, specify the sync count as 0.

This API can be called with temporary user credentials provided by Cognito Identity or with developer credentials.

Request Syntax

POST /identitypools/IdentityPoolId/identities/IdentityId/datasets/DatasetName HTTP/1.1 x-amz-Client-Context: ClientContext Content-type: application/json { "DeviceId": "string", "RecordPatches": [ { "DeviceLastModifiedDate": number, "Key": "string", "Op": "string", "SyncCount": number, "Value": "string" } ], "SyncSessionToken": "string" }

URI Request Parameters

The request uses the following URI parameters.

ClientContext

Intended to supply a device ID that will populate the lastModifiedBy field referenced in other methods. The ClientContext field is not yet implemented.

DatasetName

A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.' (dot).

Length Constraints: Minimum length of 1. Maximum length of 128.

Pattern: [a-zA-Z0-9_.:-]+

Required: Yes

IdentityId

A name-spaced GUID (for example, us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region.

Length Constraints: Minimum length of 1. Maximum length of 55.

Pattern: [\w-]+:[0-9a-f-]+

Required: Yes

IdentityPoolId

A name-spaced GUID (for example, us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region.

Length Constraints: Minimum length of 1. Maximum length of 55.

Pattern: [\w-]+:[0-9a-f-]+

Required: Yes

Request Body

The request accepts the following data in JSON format.

DeviceId

The unique ID generated for this device by Cognito.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 256.

Required: No

RecordPatches

A list of patch operations.

Type: Array of RecordPatch objects

Required: No

SyncSessionToken

The SyncSessionToken returned by a previous call to ListRecords for this dataset and identity.

Type: String

Required: Yes

Response Syntax

HTTP/1.1 200 Content-type: application/json { "Records": [ { "DeviceLastModifiedDate": number, "Key": "string", "LastModifiedBy": "string", "LastModifiedDate": number, "SyncCount": number, "Value": "string" } ] }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

Records

A list of records that have been updated.

Type: Array of Record objects

Errors

For information about the errors that are common to all actions, see Common Errors.

InternalErrorException

Indicates an internal service error.

HTTP Status Code: 500

InvalidLambdaFunctionOutputException

The AWS Lambda function returned invalid output or an exception.

HTTP Status Code: 400

InvalidParameterException

Thrown when a request parameter does not comply with the associated constraints.

HTTP Status Code: 400

LambdaSocketTimeoutException

This exception is thrown when your Lambda function fails to respond within 5 seconds. For more information, see Amazon Cognito Events.

HTTP Status Code: 400

LambdaThrottledException

AWS Lambda throttled your account, please contact AWS Support

HTTP Status Code: 429

LimitExceededException

Thrown when the limit on the number of objects or operations has been exceeded.

HTTP Status Code: 400

NotAuthorizedException

Thrown when a user is not authorized to access the requested resource.

HTTP Status Code: 403

ResourceConflictException

Thrown if an update can't be applied because the resource was changed by another call and this would result in a conflict.

HTTP Status Code: 409

ResourceNotFoundException

Thrown if the resource doesn't exist.

HTTP Status Code: 404

TooManyRequestsException

Thrown if the request is throttled.

HTTP Status Code: 429

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: