Swift DynamoDB Mapper Submitting Null Values

I am trying to use DynamoDB using the iOS Swift SDK. I use Cognito with Facebook as an external identity provider. Cognito works fine - I checked user synchronization and it works fine, so I believe that I have authentication installed. This is how I configure the SDK (I have the actual values ​​of my identifier pool in my code):

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1, identityPoolId:"<my-identity-pool-id>", identityProviderManager: FacebookProvider()) let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider) AWSServiceManager.default().defaultServiceConfiguration = configuration 

And here is my DynamoDB class mapped:

 import Foundation import AWSDynamoDB class SavedItem : AWSDynamoDBObjectModel, AWSDynamoDBModeling { var userId : Int? var timestamp : Int? class func dynamoDBTableName() -> String { return "my-table" } class func hashKeyAttribute() -> String { return "userId" } class func rangeKeyAttribute() -> String { return "timestamp" } } 

I verified that my code has the correct table and attribute names and that the hash and range key values ​​in the table are identical, including case sensitivity, with the fields in my SavedItem class.

This is how I create the mapper instance:

 let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default() let savedItem = SavedItem() savedItem?.userId = 1 savedItem?.timestamp = 2 dynamoDBObjectMapper.save(savedItem!).continueWith(block: { (task:AWSTask<AnyObject>!) -> Any? in if let error = task.error as? NSError { print("The request failed. Error: \(error)") } else { print("Save callback executing") } return nil }) 

This code is more or less directly from the AWS sample documentation. But here is what I will return to the console when this code executes:

 Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" UserInfo={__type=com.amazon.coral.validate#ValidationException, message=Supplied AttributeValue is empty, must contain exactly one of the supported datatypes} 

I ran into console logging before debugging, and it looks like it is not sending any attributes from the SavedItem object. Here's what in the console for the save request body:

 Request body: {"Key":{"userId":{},"timestamp":{}},"TableName":"my-table","AttributeUpdates":{}} 

Any idea why the values ​​do not fall into the body of the save request?

Using aws-sdk-ios v2.6.1 in Swift 4 on iOS 11.

0
source share
2 answers

The problem seems to be of type userId and timestamp . Changing them from Int to NSNumber problem.

0
source

Yes, I faced the same problem. and after the battle for 3 days. I found that AWSDynamoDBObjectModel does not support fast 4. try in fast version 3. You will get success.

-1
source

Source: https://habr.com/ru/post/1243489/


All Articles