What is the functional difference, if any, between Clients and Resources?
Are they functionally equivalent?
Under what conditions would you elect to invoke a Boto3 Resource vs. a Client (and vice-versa)?
What is the functional difference, if any, between Clients and Resources?
Are they functionally equivalent?
Under what conditions would you elect to invoke a Boto3 Resource vs. a Client (and vice-versa)?
Resources are just a resource-based abstraction over the clients. They can't do anything the clients can't do, but in many cases they are nicer to use. They actually have an embedded client that they use to make requests. The downside is that they don't always support 100% of the features of a service.
Always create a resource
. It has the important methods you will need, such as Table
. If you happen to need a client
object, it's there ready for use, just ask for .meta.client
:
import boto3
dynamodb = boto3.resource(service_name='dynamodb', endpoint_url='http://localhost:8000')
try:
dynamodb.create_table(...)
except dynamodb.meta.client.exceptions.ResourceInUseException:
logging.warn('Table already exists')
table = dynamodb.Table(table_name)
response = table.get_item(...)