Reputation: 11755
Here is some working code, extracting one item from a DynamoDB table:
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default(),
scanExpression = AWSDynamoDBScanExpression()
scanExpression.limit = 1
dynamoDbObjectMapper.scan(MyTable.self, expression: scanExpression) {
[weak self] (output: AWSDynamoDBPaginatedOutput?, error: Error?) in
if error != nil {
print("The request failed. Error: \(String(describing: error))")
}
if output != nil {
currentItem = output!.items[0]
.. Do useful things with the output ..
.........
// Now I want to erase currentItem from the DynamoDB table!
}
}
I would like to erase currentItem from the table, once this code is run. What is the best way to do it?
I guess that must not be too difficult, but I can't find the solution (meaning a swift example) by searching the net.
Upvotes: 1
Views: 225
Reputation: 11755
Just in case someone else hits the same question.
Here is how I solved it:
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
dynamoDbObjectMapper.remove(objectToDelete).continueWith(block: {
(task:AWSTask<AnyObject>!) -> Any? in
if let error = task.error {
print("Error in \(#function):\n\(error)")
}
return nil
})
Upvotes: 2