How to scan a dynamodb table using apache camel?

不问归期 提交于 2020-08-10 19:12:15

问题


I have a camel rest api which scans a DynamoDb table. The code is like so ->

.post("dynamodb-scan-table")
   .route()
  .toD("aws2-ddb://user?accessKey=insert&secretKey=insert&region=us-east-1&operation=Scan")
  .endRest();

This returns all the items in my table. My problem is how to scan the table based on a certain condition. In the camel docs, it is given that there is a header CamelAwsDdbScanFilter which is of the type Map<String, Condition> needs to be set in order to achieve the solution for my problem. I have a table of users and suppose I want to retrieve all the users with FirsName = Will. How do I implement the Map<String, Condition> in order to achieve this? Basically I am not sure what to put in the Condition of the map.


回答1:


You can find example usage in ScanCommandTest.

For condition FirstName eq Will the filter could be something like:

exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, new HashMap<String, Condition>(){{
    put("FirsName", new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS("Will")));
}});


来源:https://stackoverflow.com/questions/63124977/how-to-scan-a-dynamodb-table-using-apache-camel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!