Reputation: 35
I have tried many different ways to save an item to Dynamo DB however I keep on getting the same error:
UserInfo={__type=com.amazon.coral.validate#ValidationException, message=Supplied AttributeValue is empty, must contain exactly one of the supported datatypes}
Here is my model file:
// ImageTable.swift
// MySampleApp
//
//
// Copyright 2018 Amazon.com, Inc. or its affiliates (Amazon). All Rights Reserved.
//
// Code generated by AWS Mobile Hub. Amazon gives unlimited permission to
// copy, distribute and modify it.
//
// Source code generated from template: aws-my-sample-app-ios-swift v0.21
//
import Foundation
import UIKit
import AWSDynamoDB
class ImageTable: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var _imageID: String?
var _kValue: NSNumber?
var _latitude: NSNumber?
var _longitude: NSNumber?
class func dynamoDBTableName() -> String {
return "sendit-mobilehub-1219842108-ImageTable"
}
class func hashKeyAttribute() -> String {
return "_imageID"
}
class func rangeKeyAttribute() -> String {
return "_kValue"
}
override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
return [
"_imageID" : "imageID",
"_kValue" : "k-value",
"_latitude" : "latitude",
"_longitude" : "longitude",
]
}
}
Here is the code that I use to try to save the data:
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
let imageTable: ImageTable = ImageTable()
imageTable._imageID = AWSIdentityManager.default().identityId
print(imageTable._imageID)
imageTable._kValue = NSNumber(value: 1)
imageTable._latitude = NSNumber(value: 1)
imageTable._longitude = NSNumber(value: 1)
//Save a new item
dynamoDbObjectMapper.save(imageTable, completionHandler: {
(error: Error?) -> Void in
if let error = error {
NSLog("Amazon DynamoDB Save Error: \(error)")
return
}
NSLog("An item was saved.")
})
Steps I Have already tried:
Thanks!
Upvotes: 1
Views: 2196
Reputation: 1441
Limits of DynamoDB for attributes: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-attributes. An attribute value cannot be an empty String or empty Set (String Set, Number Set, or Binary Set). However, empty Lists and Maps are allowed.
Can you check if all the four fields in the table have valid non-empty values? My suspect is that AWSIdentityManager.default().identityId
is empty. You have to setup authentication using AWS Auth SDK in your iOS app so that this identity id is a valid and non-empty string. Ref: https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-user-sign-in.html
Upvotes: 1