GithubHelp home page GithubHelp logo

Using non-default profile about boto3 HOT 8 CLOSED

boto avatar boto commented on August 24, 2024
Using non-default profile

from boto3.

Comments (8)

TheDigitalNinja avatar TheDigitalNinja commented on August 24, 2024 17

@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

from boto3.

revmischa avatar revmischa commented on August 24, 2024 9

That's a terrible answer

from boto3.

danielgtaylor avatar danielgtaylor commented on August 24, 2024

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

from boto3.

zen4ever avatar zen4ever commented on August 24, 2024

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

from boto3.

danielgtaylor avatar danielgtaylor commented on August 24, 2024

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

from boto3.

zen4ever avatar zen4ever commented on August 24, 2024

Great, thanks 👍

from boto3.

revmischa avatar revmischa commented on August 24, 2024

How do you get a list of available profiles?

from boto3.

 avatar commented on August 24, 2024

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

from boto3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.