Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-default profile #21

Closed
zen4ever opened this issue Nov 15, 2014 · 8 comments
Closed

Using non-default profile #21

zen4ever opened this issue Nov 15, 2014 · 8 comments
Assignees
Labels
feature-request This issue requests a feature. pending-release This issue will be fixed by an approved PR that hasn't been released yet. question

Comments

@zen4ever
Copy link

Is there a simple way to use a non-default profile by specifying it's name?
Like on boto there is

boto.connect_ec2(profile_name="dev-profile")

I see that I can construct a session with credentials and region, but I don't see an ability to just refer to the profile's name

@danielgtaylor
Copy link
Member

@zen4ever unfortunately this isn't exposed in this way yet, but I do think it's something we should add. Here are a couple of workarounds that work right now:

  1. Set the BOTO_DEFAULT_PROFILE environment variable to the name of the profile. Docs for env vars
  2. Use your own Botocore session:
import botocore.session
import boto3

# Set your profile name on a low-level Botocore session
session = botocore.session.get_session()
session.profile = 'my-profile-name'

# Tell Boto 3 to use that session by default
boto3.setup_default_session(botocore_session=session)

# Now create a resource
ec2 = boto3.resource('ec2')

Piping a profile name in through the client and resource calls will require some changes on the Botocore side, so I'll investigate how best to approach this. Thanks for the feedback, and sorry I overlooked this use case! 👍

@zen4ever
Copy link
Author

Nice. Botocore session seems like a good workaround for now. :-)

@danielgtaylor danielgtaylor added the feature-request This issue requests a feature. label Dec 17, 2014
@danielgtaylor
Copy link
Member

@zen4ever it's now possible to set a profile name without dropping down to Botocore sessions. Please take a look at the docs in #69 and let me know if you have any other questions!

@danielgtaylor danielgtaylor added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Feb 27, 2015
@zen4ever
Copy link
Author

Great, thanks 👍

@revmischa
Copy link

How do you get a list of available profiles?

@ghost
Copy link

ghost commented Feb 28, 2017

@revmischa You can look at your config file at ~/.aws/config or its corresponding ~/.aws/credentials

@revmischa
Copy link

That's a terrible answer

@TheDigitalNinja
Copy link

@revmischa This is what I was able to come up with. Should print out all available boto profiles.

#!/usr/bin/env python

import boto3

session = boto3.Session()
print session.available_profiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue requests a feature. pending-release This issue will be fixed by an approved PR that hasn't been released yet. question
Projects
None yet
Development

No branches or pull requests

4 participants