DynamoDB Scan returning an empty array

0

I'm attempting to utilize a Java program to interface with DynamoDB to retrieve a primary key and eventually turn it into a list of strings so that it can be sent over as a POST request to a website that needs these details. I'm able to send over hard coded arrays up to the frontend website, and it's rendered nicely. However, attempting to scan and retrieve a primary key string in each item of the table yields an empty array. Any help would be appreciated. The table only has a few items.

public List<String> getAllImageIds() { //HomeScreen_Entity.java
		
		ScanRequest scanRequest = new ScanRequest()
				.withTableName("tableName")
				.withAttributesToGet("image_id");
		ScanResult result = dynamoDBClient.scan(scanRequest);
		List<String> imageIds = new ArrayList<>();
		for (Map<String, com.amazonaws.services.dynamodbv2.model.AttributeValue> item : result.getItems()) {
			if (item.containsKey("image_id")) {
				imageIds.add(item.get("image_id").getS());
			}
		}
		System.out.println("The first item in imageIDs is: " + imageIds.get(0));
		return imageIds;
		
	}
  • Can you share a single item from your table?

  • A single item from the table: {"jeo_1", "feature_exec","aut-rf", "labautomate"}, image_id being first (partition key), branch being 2nd, tag being 3rd, repo being 4th. No sort key.

  • DynamoDB is not schema based, can you share the item as you view it in the DynamoDB Web Console, which contains key-value pairs in JSON output?

  • I figured out my issue but thank you. It was due to a lack of permissions to do the scan operation, I got this fixed. Thanks again.

ronb
asked 2 months ago749 views
2 Answers
-1

Hello.

Does this mean that the result of printing the contents of "result" is an empty array?
Can you confirm that "result" contains the scan result?
By the way, are the values ​​specified for "image_id" and "tableName" correct?

Also, I don't think it's very relevant, but since "AttributesToGet" is an old method, I think it would be better to use ".withProjectionExpression".
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.AttributesToGet.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ScanJavaDocumentAPI.html

profile picture
EXPERT
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
  • Use comments for asking questions, not answers.

-2

I haven't had the chance to print the result in the file. However, this "result" is converted into a list of strings and sent as an API response to a website, and over there, the list of strings (result) is empty. So, I'm thinking that the problem could be this function that I posted above. The API response part is fine, because if I create a random array with values and send it as an API response, that array is rendered fine on the website.

ronb
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions