本文整理汇总了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