difference between client and resource in boto3

+1 vote
Feb 28 in AWS by anonymous
441 views

1 answer to this question.

+1 vote

The main difference between Client and Resources are as follows:

Client Resource
  • low-level service access
  • generated from service description
  • exposes botocore client to the developer
  • typically maps 1:1 with the service API
  • higher-level, object-oriented API
  • generated from resource description
  • uses identifiers and attributes
  • has actions (operations on resources)
  • exposes subresources and collections

answered Mar 1 by Priyaj
• 56,520 points
Please give some examples to understand the difference better.

Here's an example of using boto client-level access to an s3 bucket:

import boto3

    client = boto3.client('s3')
    response = client.list_objects(Bucket='example')
    for content in response['cont']:
        obj_dict = client.get_object(Bucket='example', Key=cont['Key'])
        print(cont['Key'], obj_dict['LastModified'])

an example of using boto resource-level access to an s3 bucket:

import boto3

    s3 = boto3.resource('s3')
    bucket = s3.Bucket('example')
    for obj in bucket.objects.all():
        print(obj.key, obj.last_modified)

Related Questions In AWS

0 votes
1 answer

What is difference between commands and container commands in Elastic Beanstalk?

The major difference between these two pieces ...READ MORE

answered Sep 12, 2018 in AWS by Archana
• 4,090 points
119 views
+1 vote
1 answer
+2 votes
10 answers

Difference between s3n, s3a and s3?

S3 Native FileSystem (URI scheme: s3n) A ...READ MORE

answered Oct 25, 2018 in AWS by Rishab rohan
6,433 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 226 views
0 votes
1 answer