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?
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
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.
Client is a low level interface where you must work with DynamoDB items using DynamoDB JSON:
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:
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.