While I was referring to the sample codes to upload a file to S3 I found the following two ways.
Using boto3.resource.put_object():
s3_resource = boto3.resource('s3')
s3_resource.put_object(Bucket = BUCKET, Key = 'test', Body= b'some data')
Using boto3.s3.transfer.upload_file():
client = boto3.client('s3')
transfer = S3Transfer(client)
transfer.upload_file('/my_file', BUCKET, 'test')
I could not figure out the difference between the two ways. Are there any advantages of using one over another in any specific use cases. Can anyone please elaborate. Thank you.
00:00 Boto3's primary function is to make AWS API calls for you. It extracts these APIs in two main ways: clients and resources. Clients give you low-level service access, while resources provide an object-oriented way of working with these services.
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.
There is likely no difference - boto3 sometimes has multiple ways to achieve the same thing. See http://boto3.readthedocs.io/en/latest/guide/s3.html#uploads for more details on uploading files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With