Reputation: 99
I'm working on some automation using AWS Boto3 SDK. I Couldn't get to know what is the difference between the Client(low-level) and Resource(high-level)
What is the difference between Low-Level(Client) and High-Level(Resource) here?
Upvotes: 7
Views: 4062
Reputation: 7
Clients provide a low-level interface to the AWS service. Their definitions are generated by a JSON service description present in the botocore library. The botocore package is shared between boto3 as well as the AWS CLI.
s3 = boto3.client("s3") response = s3.list_buckets()
print("Existing buckets:") for bucket in response['Buckets']: print(f'{bucket["Name"]}')
Resources are a higher-level abstraction compared to clients. They are generated from a JSON resource description that is present in the boto library itself. E.g. this is the resource definition for S3.
Resources provide an object-oriented interface for interacting with various AWS services. Resources can be instantiated like the following:
# S3 bucket identifier
s3 = boto3.resource("s3")
bucket = s3.Bucket(name="my_bucket")
To summarize, resources are higher-level abstractions of AWS services compared to clients. Resources are the recommended pattern to use boto3 as you don’t have to worry about a lot of the underlying details when interacting with AWS services. As a result, code written with Resources tends to be simpler.
However, Resources aren’t available for all AWS services. In such cases, there is no other choice but to use a Client instead.
Upvotes: 0
Reputation: 428
The references made here, as per my understanding is towards low-level and high-level interfaces used in API programming. Here it goes,
high-level interface, are designed to enable the programmer to write code in shorter amount of time and to be less involved with the details of the software module or hardware device that is performing the required services. Which is in direct contrast with the other one.
low-level interface, are more detailed allowing the programmer to manipulate functions within a software module or within hardware at very granular level.
In AWS, when you use Boto3 for API programming, Clients provide the low-level interface as closely with service APIs. Which means, all service operations will be supported by clients.Whereas, the Resources provide a hig-level interface which means differently than the raw low-level calls provided by Clients.
Upvotes: 4