Interview Prep/Python for DevOps/boto3 & AWS automation

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")
All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation