Skip to content

Using non-default profileΒ #21

Closed
Closed

Description

@andrew-kurin

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

Activity

  1. danielgtaylor commented on Nov 18, 2014

    @danielgtaylor
    Contributor

    @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! πŸ‘

  2. andrew-kurin commented on Nov 18, 2014

    @andrew-kurin
    Author

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

  3. danielgtaylor commented on Feb 27, 2015

    @danielgtaylor
    Contributor

    @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!

  4. added
    pending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.
    on Feb 27, 2015
  5. andrew-kurin commented on Feb 27, 2015

    @andrew-kurin
    Author

    Great, thanks πŸ‘

  6. added a commit that references this issue on Mar 5, 2015
    530fde5
  7. revmischa commented on Jul 5, 2016

    @revmischa

    How do you get a list of available profiles?

  8. revmischa commented on Feb 28, 2017

    @revmischa

    That's a terrible answer

  9. TheDigitalNinja commented on Mar 6, 2017

    @TheDigitalNinja

    @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

Metadata

Metadata

Assignees

Labels

feature-requestThis issue requests a feature.pending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions