What is the difference between a boto3 Session, client and resource?
BeginnerConceptboto3 & AWS automation
Answer
- Session: holds configuration, credentials and the default region.
boto3.client(...)uses a hidden default session. - Client: low-level, one method per API operation, returns plain dicts, covers every service and every operation. Thread-safe.
- Resource: higher-level object model (
s3.Bucket("x").objects.all()), available for a handful of services. AWS has stopped adding features to resources, so new code should use clients.
session = boto3.Session(profile_name="prod", region_name="ap-south-1")
ec2 = session.client("ec2")
More on boto3 & AWS automation
How does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?BeginnerWhat are waiters, and why use them instead of `sleep` loops?Intermediate