I have a dynamodb table called environments
and a column within that table called env_name
When running the class in the command line:
java -cp target/sharedlibraries.jar com.mimo.sharedlibraries.fetchCMDBtable environments env_name
i get an empty list instead of a list full of environment names.
Here is my class i am using:
public class fetchCMDBtable {
public static void main(String[] args)throws Exception {
//default values
if (args.length != 2) {
System.out.println("Not enough args!");
System.exit(1);
}
String tableName = args[0]; //environments
String tableColumn = args[1]; //env_name
DynamoDbClient client = DynamoDbClient.builder()
.region(Region.EU_WEST_1)
.build();
CMDB(client,tableName,tableColumn);
System.out.println(CMDB(client, tableName, tableColumn));
client.close();
}
public static List<String> CMDB(DynamoDbClient client,String tableName, String tableColumn) throws Exception {
List<String> ListValues = new ArrayList<>();
try {
ScanRequest scanRequest = ScanRequest.builder()
.tableName(tableName)
.build();
ScanResponse response = client.scan(scanRequest);
for (Map<String, AttributeValue> item : response.items()){
Set<String> keys = item.keySet();
for (String key : keys) {
if (key == tableColumn) {
ListValues.add(item.get(key).s()) ;
}
}
}
} catch (DynamoDbException e){
e.printStackTrace();
System.exit(1);
}
return ListValues;
}
}
CodePudding user response:
try to use key.equals(tableColumn)
instaed of key == tableColumn