14

AWS DynamoDB Batch Get Request - iOS

 3 years ago
source link: https://www.codesd.com/item/aws-dynamodb-batch-get-request-ios.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

AWS DynamoDB Batch Get Request - iOS

advertisements

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 a error

validation error detected: Value null at 'requestItems.rip.member.keys' failed to satisfy constraint

I understand this as the values not being passed correctly but I can't see what the issue is with my code

//Create Request Values
AWSDynamoDBGetItemInput *getItem = [AWSDynamoDBGetItemInput new];
AWSDynamoDBAttributeValue *hashValue = [AWSDynamoDBAttributeValue new];
hashValue.S = @"User Test";
getItem.key = @{@"ripId": hashValue};

//Create Request Values 2
AWSDynamoDBGetItemInput *getItem2 = [AWSDynamoDBGetItemInput new];
AWSDynamoDBAttributeValue *hashValue2 = [AWSDynamoDBAttributeValue new];
hashValue2.S = @"User Test";
getItem2.key = @{@"chat": hashValue2};

//Combine to Batch Request
AWSDynamoDBBatchGetItemInput * batchFetch = [AWSDynamoDBBatchGetItemInput new];
batchFetch.requestItems = @{ @"rip": getItem,
                             @"chat": getItem,};

[[dynamoDB batchGetItem:batchFetch] continueWithBlock:^id(BFTask *task) {
    if (!task.error) {

        NSLog(@"BOY SUCCES");

    } else {
        NSLog(@" NO BOY SUCCESS %@",task.error);
    }
    return nil;
}];

Searched the internet high and low but cannot see a working example of a batch request using iOS Objective C (or swift for that matter).

I have tested both variables on a single Get request and they both work.


You forgot to wrap around AWSDynamoDBAttributeValue in AWSDynamoDBKeysAndAttributes. Here is a simple example from AWSDynamoDBTests.m:

AWSDynamoDBKeysAndAttributes *keysAndAttributes = [AWSDynamoDBKeysAndAttributes new];
keysAndAttributes.keys = @[@{@"hashKey" : attributeValue1},
                           @{@"hashKey" : attributeValue2}];
keysAndAttributes.consistentRead = @YES;

AWSDynamoDBBatchGetItemInput *batchGetItemInput = [AWSDynamoDBBatchGetItemInput new];
batchGetItemInput.requestItems = @{table1Name: keysAndAttributes};




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK