DynamoDB保存到数据库

DynamoDB保存到数据库

问题描述:

我是AWS的新手,我试图使用新闻表的aws示例将数据保存到我的数据库。DynamoDB保存到数据库

我连这个功能主要故事板按钮:

@IBAction func addButton(_ sender: Any) { 

    let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default() 

    //Create data object using data models you downloaded from Mobile Hub 
    let newsItem: News = News(); 

    // Use AWSIdentityManager.default().identityId here to get the user identity id. 
    newsItem._userId = "us-east-1:74c8f7ce-244b-4476-963e-0dcb3216f406" 
    newsItem._articleId = "0123" 
    newsItem._title = "Banana" 
    newsItem._author = "Logan" 
    newsItem._content = "Should I stay or should I go now?" 
    newsItem._category = "Food" 


    //Save a new item 
    dynamoDbObjectMapper.save(newsItem, completionHandler: { 
     (error: Error?) -> Void in 

     if let error = error { 
      print("Amazon DynamoDB Save Error: \(error)") 
      return 
     } 
     print("An item was saved.") 
    }) 

} 

但是当我按下按钮,我得到: mazon DynamoDB Save Error: 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}

我的新闻领域是:

 override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] { 
    return [ 
      "_userId" : "userId", 
      "_articleId" : "articleId", 
      "_author" : "author", 
      "_category" : "category", 
      "_content" : "content", 
      "_title" : "title", 
    ] 
} 
+0

哪些相关dynamoDB表必填字段? –

我同样的问题,并且我解决了在News()中eery变量中添加@objc,例如

class News: AWSDynamoDBObjectModel, AWSDynamoDBModeling { 
    @objc var id: String? 
    @objc var type: String? 
    @objc var cc: String? 
} 

如果添加@objc迫使换到NS对象,这是AWS的移动SDK中的错误...

+0

这真的帮了我。 Upvoting。谢谢! – Macondo2Seattle