我正在尝试在名为Users
的DynamoDB表中插入新记录。我从表中获取数据。但每当我尝试插入新记录时,我都会收到以下错误 -
AWSiOSSDKv2 [Verbose] AWSURLResponseSerialization.m line:86 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body: [{"__type":"com.amazon.coral.validate#ValidationException","message":"Supplied AttributeValue is empty, must contain exactly one of the supported datatypes"}]
我的问题是导致此例外的原因以及我得到它的原因是什么?我确信我没有任何空变量(你可以在附件中看到)
有关此问题的信息:
这是我想要做的完整日志 -
AWSiOSSDKv2 [Verbose] AWSURLRequestSerialization.m line:111 | -[AWSJSONRequestSerializer serializeRequest:headers:parameters:] | Request body: [{"Key":{"phone_no":{"S":"Empty"}},"TableName":"Users","AttributeUpdates":{"signed_in_counts":{"Action":"DELETE"},"account_owner":{"Value":{"S":"Empty"},"Action":"PUT"},"email_id":{"Value":{"S":"Empty"},"Action":"PUT"},"catalog_ids":{"Value":{},"Action":"PUT"},"account_creation_date":{"Value":{"S":"Empty"},"Action":"PUT"},"title":{"Value":{"S":"Empty"},"Action":"PUT"},"date_of_birth":{"Value":{"S":"Empty"},"Action":"PUT"},"defaultOnlineStatus":{"Action":"DELETE"},"chat_enabled":{"Value":{"S":"YES"},"Action":"PUT"},"username":{"Value":{"S":"Empty"},"Action":"PUT"},"address_line1":{"Value":{"S":"Empty"},"Action":"PUT"},"last_name":{"Value":{"S":"Empty"},"Action":"PUT"},"last_date_of_sign_out":{"Value":{"S":"Empty"},"Action":"PUT"},"total_referrals":{"Action":"DELETE"},"last_date_signed_in":{"Value":{"S":"Empty"},"Action":"PUT"},"first_name":{"Value":{"S":"Empty"},"Action":"PUT"},"activated":{"Value":{"S":"YES"},"Action":"PUT"}}}]
2015-04-20 15:44:53.434 Barnc[534:65423] AWSiOSSDKv2 [Debug] AWSSignature.m line:305 | -[AWSSignatureV4Signer signRequestV4:] | AWS4 Canonical Request: [POST
/
accept-encoding:
content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
user-agent:aws-sdk-iOS/2.1.0 iPhone-OS/8.3 en_IN
x-amz-date:20150420T101453Z
x-amz-security-token:XXX
x-amz-target:DynamoDB_20120810.UpdateItem
accept-encoding;content-type;host;user-agent;x-amz-date;x-amz-security-token;x-amz-target
93a6af5de49c12a33621c58cbc3ea7c9bbd8cd59660531bef10ea81c36acb06f]
2015-04-20 15:44:53.436 Barnc[534:65423] AWSiOSSDKv2 [Debug] AWSSignature.m line:306 | -[AWSSignatureV4Signer signRequestV4:] | payload {"Key":{"phone_no":{"S":"Empty"}},"TableName":"Users","AttributeUpdates":{"signed_in_counts":{"Action":"DELETE"},"account_owner":{"Value":{"S":"Empty"},"Action":"PUT"},"email_id":{"Value":{"S":"Empty"},"Action":"PUT"},"catalog_ids":{"Value":{},"Action":"PUT"},"account_creation_date":{"Value":{"S":"Empty"},"Action":"PUT"},"title":{"Value":{"S":"Empty"},"Action":"PUT"},"date_of_birth":{"Value":{"S":"Empty"},"Action":"PUT"},"defaultOnlineStatus":{"Action":"DELETE"},"chat_enabled":{"Value":{"S":"YES"},"Action":"PUT"},"username":{"Value":{"S":"Empty"},"Action":"PUT"},"address_line1":{"Value":{"S":"Empty"},"Action":"PUT"},"last_name":{"Value":{"S":"Empty"},"Action":"PUT"},"last_date_of_sign_out":{"Value":{"S":"Empty"},"Action":"PUT"},"total_referrals":{"Action":"DELETE"},"last_date_signed_in":{"Value":{"S":"Empty"},"Action":"PUT"},"first_name":{"Value":{"S":"Empty"},"Action":"PUT"},"activated":{"Value":{"S":"YES"},"Action":"PUT"}}}
2015-04-20 15:44:53.439 Barnc[534:65423] AWSiOSSDKv2 [Debug] AWSSignature.m line:322 | -[AWSSignatureV4Signer signRequestV4:] | AWS4 String to Sign: [AWS4-HMAC-SHA256
20150420T101453Z
20150420/us-east-1/dynamodb/aws4_request
3d4769e2a1f73aee21f7ef26ae389183852118fbf078261e1a293262f0ac97d3]
2015-04-20 15:44:54.748 Barnc[534:66289] AWSiOSSDKv2 [Debug] AWSURLResponseSerialization.m line:81 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response header: [{
"Content-Length" = 156;
"Content-Type" = "application/x-amz-json-1.0";
Date = "Mon, 20 Apr 2015 10:14:53 GMT";
"x-amz-crc32" = 1541720790;
"x-amzn-RequestId" = XXX;
}]
2015-04-20 15:44:54.748 Barnc[534:66289] AWSiOSSDKv2 [Verbose] AWSURLResponseSerialization.m line:86 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body:
[{"__type":"com.amazon.coral.validate#ValidationException","message":"Supplied AttributeValue is empty, must contain exactly one of the supported datatypes"}]
The request failed. Error: [Error Domain=com.amazonaws.AWSDynamoDBErrorDomain Code=0 "The operation couldn’t be completed. (com.amazonaws.AWSDynamoDBErrorDomain error 0.)" UserInfo=0x1760c310 {message=Supplied AttributeValue is empty, must contain exactly one of the supported datatypes, __type=com.amazon.coral.validate#ValidationException}]
我试图在数据模型中放置虚拟数据,以便没有任何空变量。但它似乎没有用。
以下是我插入记录的方式 -
-(void)saveUser:(BarncUser*)user{
[user autoValidate];
[[dynamoDBObjectMapper save:user.amazonUser]
continueWithBlock:^id(BFTask *task) {
if (task.error) {
NSLog(@"The request failed. Error: [%@]", task.error);
}
if (task.exception) {
NSLog(@"The request failed. Exception: [%@]", task.exception);
}
if (task.result) {
//Do something with the result.
}
return nil;
}];
}
我的数据模型看起来像这样 -
@interface AmazonUser : AWSDynamoDBObjectModel <AWSDynamoDBModeling>
@property (nonatomic, strong) NSString *phone_no;
@property (nonatomic, strong) NSString *activated;
@property (nonatomic, strong) NSMutableArray *catalog_ids;
@property (nonatomic, strong) NSNumber *defaultOnlineStatus;
@property (nonatomic, strong) NSNumber *signed_in_counts;
@property (nonatomic, strong) NSNumber *total_referrals;
@property (nonatomic, strong) NSString *account_creation_date;
@property (nonatomic, strong) NSString *email_id;
@property (nonatomic, strong) NSString *account_owner;
@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *first_name;
@property (nonatomic, strong) NSString *chat_enabled;
@property (nonatomic, strong) NSString *last_name;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *last_date_of_sign_out;
@property (nonatomic, strong) NSString *date_of_birth;
@property (nonatomic, strong) NSString *last_date_signed_in;
@property (nonatomic, strong) NSString *address_line1;
- (void)createDummy;
@end
@implementation AmazonUser
+ (NSString *)dynamoDBTableName {
return @"Users";
}
+ (NSString *)hashKeyAttribute {
return @"phone_no";
}
- (void)createDummy{
self.phone_no = @"Empty";
self.activated = @"YES";
self.catalog_ids = [[NSMutableArray alloc]init];
self.defaultOnlineStatus = 0;
self.signed_in_counts = 0;
self.total_referrals = 0;
self.account_creation_date = @"Empty";
self.email_id = @"Empty";
self.account_owner = @"Empty";
self.username = @"Empty";
self.first_name = @"Empty";
self.chat_enabled = @"YES";
self.last_name = @"Empty";
self.title = @"Empty";
self.last_date_of_sign_out = @"Empty";
self.date_of_birth = @"Empty";
self.last_date_signed_in = @"Empty";
self.address_line1 = @"Empty";
}
答案 0 :(得分:5)
从日志开始,NSMutableArray catalog_ids
仍为空:
catalog_ids":{"Value":{},"Action":"PUT"}
在DynamoDB Data Model的文档中,提到DynamoDB不支持多值数据类型的空集。尝试使用非零值初始化数组。