0

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?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Jason
  • 497
  • 3
  • 9
  • 27
  • Resource methods are more 'Pythonic', whereas Client methods map directly to API calls. It can sometimes be difficult to know which permissions to assign to Resource methods because the underlying API call is not directly referenced. – John Rotenstein Oct 01 '22 at 22:37

2 Answers2

0

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.

ashraf minhaj
  • 504
  • 2
  • 14
0

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.

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31