Search code examples
aws-lambdaamazon-dynamodbdynamodb-queries

dynamodb keyconditionexpression vs filterexpression costs?


I would like to know if there are costs diference when i make a query in dynamodb and use a filterexpression instead of a keyconditionexpression.

Do i need to create indexes to use filterexpressions ?

Do it increase the costs of queries ?


Solution

  • DynamoDB Query Operations, we can provide three things to select/filter data.

    • Partition Key: we must provide it in KeyConditionExpression
    • Range/Sort Key: We can provide to narrow scope of query in KeyConditionExpression
    • Any other attribute: we can provide to further limit the results in FilterExpression

    Two points to remember:

    • Amount of RCU is consumed by a query depends only on KeyConditionExpression, so, specifying Range/Sort Key will limit the amount of data that is read/query which helps save cost.
    • FilterExpression is applied after a Query finishes, but before the results are returned. This doesn't affect RCU and doesn't affect cost, however, this will help amount of data returned to client. if client is outside AWS, then we will only save Network Data out cost.