Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use dynamodb.client, dynamodb.resource and dynamodb.Table?

I am working on Dyanamodb using Boto3 and Python. One of the issues I am finding is when should we use the dynamodb.client, dynamodb.resource and dynamodb.Table?

like image 595
Shash Avatar asked Jan 31 '19 06:01

Shash


Video Answer


1 Answers

dynamodb.client provide a low level access directly to the DynamoDB apis. You can call only the apis listed here.

The service resource objects like dynamodb.resource provides a more object oriented way of access the AWS resources. DynamoDB is a fairly straightforward service in terms of the different kinds of things you create in AWS. (Basically the main object you create are tables, as opposed to a service like EC2 where you have many different kinds of objects (instances, security groups, launch configurations, etc).

The dynamodb.Table object provides a simplified way of accessing the data in the table. It will marshall and unmarshall the data automatically from the DynamoDB format to a simpler for you.

Format examples Using the dynamodb.Client data might look like this

{
  "id": {
    "S": "a unique id"
  },
  "date": {
    "N": "12345678901234"
  }
}

Whereas using the Table resource you will get data that looks like this

{
  "id": "a unique id",
  "date": 12345678901234
}

I recommend using the Table resources since it simplifies data access.

like image 136
cementblocks Avatar answered Sep 30 '22 04:09

cementblocks