AWS DynamoDB Batch Get Request - iOS

后端 未结 3 846
深忆病人
深忆病人 2021-01-03 08:29

I can perform a simple Get request on a singular table within AWS dynamoDB however when I expand it to a Batch Request across multiple tables I continue to get

3条回答
  •  被撕碎了的回忆
    2021-01-03 08:58

    Swift 3

    I was able to get the BatchGet request work with the following code. Hope this helps someone else who's struggling with the lack of Swift Docs.
  • This code assumes that you've configured your AWSServiceConfiguration in the AppDelegate application didFinishLaunchingWithOptions method.

    let DynamoDB = AWSDynamoDB.default()
    
        // define your primary hash keys
        let hashAttribute1 = AWSDynamoDBAttributeValue()
        hashAttribute1?.s = "NDlFRTdDODEtQzNCOC00QUI5LUFFMzUtRkIyNTJFNERFOTBF"
    
        let hashAttribute2 = AWSDynamoDBAttributeValue()
        hashAttribute2?.s = "MjVCNzU3MUQtMEM0NC00NEJELTk5M0YtRTM0QjVDQ0Q1NjlF"
    
        let keys: Array = [["userID": hashAttribute1], ["userID": hashAttribute2]]
    
        let keysAndAttributesMap = AWSDynamoDBKeysAndAttributes()
        keysAndAttributesMap?.keys = keys as? [[String : AWSDynamoDBAttributeValue]]
        keysAndAttributesMap?.consistentRead = true
        let tableMap = ["Your-Table-Name" : keysAndAttributesMap]
        let request = AWSDynamoDBBatchGetItemInput()
        request?.requestItems = tableMap as? [String : AWSDynamoDBKeysAndAttributes]
        request?.returnConsumedCapacity = AWSDynamoDBReturnConsumedCapacity.total
        DynamoDB.batchGetItem(request!) { (output, error) in
            if output != nil {
                print("Batch Query output?.responses?.count:", output!.responses!)
            }
            if error != nil {
                print("Batch Query error:", error!)
            }
        }
    

提交回复
热议问题