skip to Main Content

https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/dynamodb.html#service-resource

For Dynamodb webservice we have
dynamodb = boto3.resource(‘dynamodb’) and
client = boto3.client(‘dynamodb’)

Both have Query and Scan methods. Are there any pros and cons using Query on a client object vs Resource object?

2

Answers


  1. You can actually use both to interact with AWS API. But there are some differences.
    Client is a low level service access. Resource is higher level object oriented API.
    Most of the times, even on aws docs you’ll see client is being used. Unless my requirements need something else, I stick to the official docs.

    To know more in depth you can see this and this.

    Login or Signup to reply.
  2. Client is a low level interface where you must work with DynamoDB items using DynamoDB JSON:

    {"id":{"S":"some-id"}}
    

    Having to work with the lower level client is a little more difficult to construct ConditionExpressions etc…

    Resource is a high level interface where it abstracts the DynamoDB JSON and allows you to use native JSON:

    {"id":"some-id"}
    

    This simplifies how your construct your conditions but also allows parsing the result set easier, without having to call utility functions such as unmarshall.

    Performance wise there is no difference. Personally I like using the Resource level.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search