Python botocore.session.set_config_variable() Examples

The following are 4 code examples of botocore.session.set_config_variable(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module botocore.session , or try the search function .
Example #1
Source File: aws.py    From deepWordBug with Apache License 2.0 6 votes vote down vote up
def _get_botocore_session():
    if _get_botocore_session.botocore_session is None:
        LOG.debug('Creating new Botocore Session')
        LOG.debug('Botocore version: {0}'.format(botocore.__version__))
        session = botocore.session.get_session({
            'profile': (None, _profile_env_var, _profile, None),
        })
        session.set_config_variable('region', _region_name)
        session.set_config_variable('profile', _profile)
        session.register_component('data_loader', _get_data_loader())
        _set_user_agent_for_session(session)
        _get_botocore_session.botocore_session = session
        if _debug:
            session.set_debug_logger()

    return _get_botocore_session.botocore_session 
Example #2
Source File: get_token.py    From bash-lambda-layer with MIT License 6 votes vote down vote up
def get_session(self, region_name, role_arn):
        """
        Assumes the given role and returns a session object assuming said role.
        """
        session = botocore.session.get_session()
        if region_name is not None:
            session.set_config_variable('region', region_name)

        if role_arn is not None:
            sts = session.create_client(AUTH_SERVICE, region_name=region_name)
            credentials_dict = sts.assume_role(
                RoleArn=role_arn,
                RoleSessionName='EKSGetTokenAuth'
            )['Credentials']

            session.set_credentials(credentials_dict['AccessKeyId'],
                                    credentials_dict['SecretAccessKey'],
                                    credentials_dict['SessionToken'])
            return session
        else:
            return session 
Example #3
Source File: aws.py    From aws-elastic-beanstalk-cli with Apache License 2.0 6 votes vote down vote up
def _get_botocore_session():
    if _get_botocore_session.botocore_session is None:
        LOG.debug('Creating new Botocore Session')
        LOG.debug('Botocore version: {0}'.format(botocore.__version__))
        session = botocore.session.get_session({
            'profile': (None, _profile_env_var, _profile, None),
        })
        session.set_config_variable('region', _region_name)
        session.set_config_variable('profile', _profile)
        session.register_component('data_loader', _get_data_loader())
        _set_user_agent_for_session(session)
        _get_botocore_session.botocore_session = session
        if _debug:
            session.set_debug_logger()

    return _get_botocore_session.botocore_session 
Example #4
Source File: EC2InstanceConnectCLI.py    From aws-ec2-instance-connect-cli with Apache License 2.0 5 votes vote down vote up
def _get_botocore_session(profile_name=None, region=None):
        """
        Generates a botocore session with Managed SSH CLI set as the user agent

        :param profile_name: The name of a profile to use.  If not given, then the \
            default profile is used.
        :type profile_name: string
        :param region: An AWS region name to set as the default for the Botocore session
        :type region: string
        :return: A Botocore session object
        :rtype: botocore.session.Session
        """
        session = botocore.session.get_session()
        botocore_info = 'Botocore/{0}'.format(session.user_agent_version)
        if session.user_agent_extra:
            session.user_agent_extra += ' ' + botocore_info
        else:
            session.user_agent_extra = botocore_info
        session.user_agent_name = 'aws-ec2-instance-connect-cli'
        session.user_agent_version = CLI_VERSION

        """
        # Credential precedence:
        # 1. set user passed profile.
        # 2. set user passed region.
        # 3. let botocore handle the rest.
        """

        if profile_name:
            session.set_config_variable('profile', profile_name)
        if region is not None:
            session.set_config_variable('region', region)

        return session