1

In many AWS programs (not don't use S3), I have the following:

session = boto3.Session(profile_name='myname')
awsclient = session.client(service_name='s3', region_name='us-east-2', use_ssl=True)

Most examples of S3 resource look like this:

s3_resource = boto3.resource('s3')  # high-level interface

Is there a way I can get the resource from the awsclient variable above, after establishing my profile and region? Or alternatively, how can I specify the profile name on an S3 Resource?

My goal is to have some consistency from one program to the other in how we connect and specify region/credentials.

This partially answers: How to specify credentials when connecting to boto3 S3? but doesn't address how to specify region.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • Does [this](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.resource) help? – jellycsc Dec 28 '20 at 20:35
  • It helps, but doesn't show how to use client. I would like to be able to have same code from one program to the other in regards to setting up user/region. If AWS uses that for other services, why not use it on S3 service. – NealWalters Dec 28 '20 at 20:50
  • 2
    Just change `session.client()` to `session.resource()`: `s3_resouce = session.resource(service_name='s3', region_name='us-east-2', use_ssl=True)` – jordanm Dec 28 '20 at 22:08

0 Answers0