I am building an android IoT app using AWS Amplify and DynamoDB. I have an ESP32 here that publishes data the sensor data to a topic I created a rule that would store it to separate DynamoDB columns.
My code below is to sort the data in descending order according to the timestamp and return a query with a limit of 1. It works for the first time, but I noticed it returns the same item even if the database is already updated or the item is no longer in the table. I have read about DynamoDB Stream, Lambda, and IoT Device Shadow but I am new to AWS and I'm confused on which service or what method works best and is not too complex for me.
This is my code to retrieve data:
public void readById() {
Amplify.DataStore.query(
myModel.class,
Where.sorted(myModel.ID.descending()).paginated(Page.startingAt(0).withLimit(1)),
items -> {
while (items.hasNext()) {
mModel item = items.next();
retrievedId = item.getId();
Log.i("Amplify", "Id " + item.getId());
}
},
failure -> Log.e("Amplify", "Could not query DataStore", failure)
);
}
Any input is appreaciated!