本文整理匯總了Python中botocore.session.set_config_variable方法的典型用法代碼示例。如果您正苦於以下問題:Python session.set_config_variable方法的具體用法?Python session.set_config_variable怎麽用?Python session.set_config_variable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類botocore.session
的用法示例。
在下文中一共展示了session.set_config_variable方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_botocore_session
# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import set_config_variable [as 別名]
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
示例2: get_session
# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import set_config_variable [as 別名]
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
示例3: _get_botocore_session
# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import set_config_variable [as 別名]
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