• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

boto / boto3 / 247
91%

Build:
DEFAULT BRANCH: develop
Ran 27 Feb 2015 10:18PM UTC
Jobs 5
Files 11
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
247

Pull #69

travis-ci

danielgtaylor
Add profile_name option to sessions

This change makes it possible to create a session using a profile name, which
was previously only possible via an environment variable. It allows you to
create clients and resources from any number of sessions using any number of
profiles.

Given that we have the following `~/.aws/credentials`:

```ini
[default]
aws_access_key_id = DEFAULT
aws_secret_access_key = SECRET1

[dev]
aws_access_key_id = DEV
aws_secret_access_key = SECRET2

[prod]
aws_access_key_id = PROD
aws_secret_access_key = SECRET3
```

You can do the following:

```python
import boto3.session

dev = boto3.session.Session(profile_name='dev')
prod = boto3.session.Session(profile_name='prod')

s3dev = dev.resource('s3')
s3prod = prod.resource('s3')

for resource in [s3dev, s3prod]:
    print('Profile: ' + resource.profile)
    for bucket in resource.buckets.all():
        print(bucket.name)
    print('')
```

It is also possible to setup the default session with a profile:

```python
import boto3

boto3.setup_default_session(profile_name='dev')

s3 = boto3.resource('s3')
```

And of course you can still use the environment variable:

```bash
$ BOTO_DEFAULT_PROFILE=dev ipython
>>> import boto3
>>> s3dev = boto3.resource('s3')
```

Once a session is created, the profile is immutable. The `profile_name`
property is provided for convenience and just surfaces the underlying
Botocore session's profile property.

Why not provide a profile name to the `client` and `resource` methods?
Currently there is no easy way to clone a session, and the behavior of
creating a new blank session (from one which may have customizations)
leads to possibly unintended side-effects like clients without the
proper event handlers registered. This would be an additive change
should we want to revisit in the future. At this point, the change
in this commit provides a way for Boto 3 users to use multiple profiles
without resorting to creating their own Botocore sessions.

I'm definit... (continued)
Pull Request #69: Add profile_name option to sessions

4 of 4 new or added lines in 1 file covered. (100.0%)

758 of 768 relevant lines covered (98.7%)

4.92 hits per line

Jobs
ID Job ID Ran Files Coverage
1 247.1 27 Feb 2015 10:18PM UTC 0
Travis Job 247.1
2 247.2 27 Feb 2015 10:18PM UTC 0
98.31
Travis Job 247.2
3 247.3 27 Feb 2015 10:19PM UTC 0
98.7
Travis Job 247.3
4 247.4 27 Feb 2015 10:19PM UTC 0
98.7
Travis Job 247.4
5 247.5 27 Feb 2015 10:19PM UTC 0
98.31
Travis Job 247.5
Source Files on build 247
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #247
  • Pull Request #69
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc