本文整理汇总了Python中lib.aws.webservice.AWSQueryClient类的典型用法代码示例。如果您正苦于以下问题:Python AWSQueryClient类的具体用法?Python AWSQueryClient怎么用?Python AWSQueryClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AWSQueryClient类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, accessKey, secretKey, endpoint, result_format = 'json'):
'''
Constructor
'''
self._accessKey = accessKey
self._secretKey = secretKey
self._endpoint = endpoint
self._format = result_format
self._client = AWSQueryClient(self._accessKey, self._secretKey,
self._endpoint, self._format,
self._signature_version, self._api_version)
示例2: __init__
def __init__(self, accessKey, secretKey, endpoint, region, result_format="json"):
"""
Constructor
"""
self._accessKey = accessKey
self._secretKey = secretKey
self._endpoint = endpoint
self._format = result_format
self._region = region
self._client = AWSQueryClient(
self._accessKey,
self._secretKey,
self._endpoint,
self._region,
self._service_name,
self._format,
self._signature_version,
self._api_version,
)
示例3: IamClient
class IamClient(object):
'''
Web service client for IAM
'''
_signature_version = AWSSignature.SigV4
_api_version = u'2010-05-08'
_service_name = u'iam'
def __init__(self, accessKey, secretKey, result_format = 'json'):
'''
Constructor
'''
self._accessKey = accessKey
self._secretKey = secretKey
self._endpoint = IamEndpoint
self._format = result_format
self._region = IamRegion
self._client = AWSQueryClient(self._accessKey, self._secretKey,
self._endpoint, self._region,
self._service_name, self._format,
self._signature_version, self._api_version)
def call(self, request):
'''Make API call and translate AWSServiceException to more specific exception'''
try:
log.debug(request)
return_msg = self._client.call(request, self._format)
log.debug(u'Request ID: {0}'.format(return_msg.json().values()[0]\
[u'ResponseMetadata'][u'RequestId']))
return return_msg.json()
except AwsServiceException as ex:
log.debug(misc.to_unicode(ex))
# Translate general IAM exception
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.AccessDenied):
raise AccessDeniedException(ex)
elif misc.string_equal_ignore_case(ex.code, AwsErrorCode.OptInRequired):
raise OptInRequiredException(ex)
elif misc.string_equal_ignore_case(ex.code, AwsErrorCode.InsufficientPrivileges):
raise InsufficientPrivilegesException(ex)
elif misc.string_equal_ignore_case(ex.code, AwsErrorCode.InvalidParameterValue):
raise InvalidParameterValueException(ex)
elif misc.string_equal_ignore_case(ex.code, AwsErrorCode.MissingParameter):
raise MissingParameterException(ex)
elif misc.string_equal_ignore_case(ex.code, IamErrorCode.EntityAlreadyExists):
raise IamEntityAlreadyExistsException(ex)
elif misc.string_equal_ignore_case(ex.code, IamErrorCode.NoSuchEntity):
raise IamNoSuchEntityException(ex)
elif misc.string_equal_ignore_case(ex.code, IamErrorCode.MalformedPolicyDocument):
raise IamMalformedPolicyDocumentException(ex)
elif misc.string_equal_ignore_case(ex.code, IamErrorCode.LimitExceeded):
raise IamLimitExceededException(ex)
raise
#---------------------------------------
# service calls
def create_role(self, role_name, assume_role_policy_document, path = None):
request = Request()
request.set_action(u'CreateRole')
request.set_role_name(role_name)
request.set_assume_role_policy_document(assume_role_policy_document)
if path is not None:
request.set_path(path)
try:
response = self.call(request)
except AwsServiceException:
raise
role = Role.from_json(response[u'CreateRoleResponse'][u'CreateRoleResult'][u'Role'])
request_id = response[u'CreateRoleResponse'][u'ResponseMetadata'][u'RequestId']
return Response(request_id, role)
def create_instance_profile(self, instance_profile_name, path = None):
request = Request()
request.set_action(u'CreateInstanceProfile')
request.set_instance_profile_name(instance_profile_name)
if path is not None:
request.set_path(path)
try:
response = self.call(request)
except AwsServiceException:
raise
#.........这里部分代码省略.........
示例4: RdsClient
class RdsClient(object):
'''
Web service client for RDS
'''
_signature_version = AWSSignature.SigV4
_api_version = u'2012-04-23'
_service_name = u'rds'
def __init__(self, accessKey, secretKey, endpoint, region, result_format = 'json'):
'''
Constructor
'''
self._accessKey = accessKey
self._secretKey = secretKey
self._endpoint = endpoint
self._format = result_format
self._region = region
self._client = AWSQueryClient(self._accessKey, self._secretKey,
self._endpoint, self._region,
self._service_name, self._format,
self._signature_version, self._api_version)
def call(self, request):
'''Make API call and translate AWSServiceException to more specific exception'''
try:
log.debug(request)
return_msg = self._client.call(request, self._format)
log.debug(u'Request ID: {0}'.format(return_msg.json().values()[0]\
[u'ResponseMetadata'][u'RequestId']))
return return_msg.json()
except AwsServiceException as ex:
log.debug(misc.to_unicode(ex))
# Translate general RDS exception
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.OptInRequired):
raise OptInRequiredException(ex)
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.InsufficientPrivileges):
raise InsufficientPrivilegesException(ex)
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.InvalidParameterValue):
raise InvalidParameterValueException(ex)
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.MissingParameter):
raise MissingParameterException(ex)
raise
#---------------------------------------
# service calls
def describe_db_engine_versions(self, db_parameter_group_family = None, default_only = None,
engine = None, engine_version = None,
list_supported_character_sets = None,
marker = None, max_records = None):
request = Request()
request.set_action(u'DescribeDBEngineVersions')
if db_parameter_group_family is not None:
request.set_db_parameter_group_family(db_parameter_group_family)
if default_only is not None:
request.set_default_only(default_only)
if engine is not None:
request.set_engine(engine)
if engine_version is not None:
request.set_engine_version(engine_version)
if list_supported_character_sets is not None:
request.set_list_supported_character_sets(list_supported_character_sets)
if marker is not None:
request.set_marker(marker)
if max_records is not None:
request.set_max_records(max_records)
try:
response = self.call(request)
except AwsServiceException:
raise
results = response[u'DescribeDBEngineVersionsResponse']\
[u'DescribeDBEngineVersionsResult'][u'DBEngineVersions']
marker = response[u'DescribeDBEngineVersionsResponse']\
[u'DescribeDBEngineVersionsResult'][u'Marker']
request_id = response[u'DescribeDBEngineVersionsResponse']\
[u'ResponseMetadata'][u'RequestId']
engine_versions = []
for result in results:
engine_versions.append(DBEngineVersion.from_json(result))
return Response(request_id, engine_versions, marker)
def describe_db_instances(self, db_instance_identifier = None,
marker = None, max_records = None):
request = Request()
request.set_action(u'DescribeDBInstances')
if db_instance_identifier is not None:
request.set_db_instance_identifier(db_instance_identifier)
#.........这里部分代码省略.........
示例5: ElasticBeanstalkClient
class ElasticBeanstalkClient(object):
'''
Web service client for Elastic Beanstalk
'''
_signature_version = 2
_api_version = '2010-12-01'
def __init__(self, accessKey, secretKey, endpoint, result_format='json'):
'''
Constructor
'''
self._accessKey = accessKey
self._secretKey = secretKey
self._endpoint = endpoint
self._format = result_format
self._client = AWSQueryClient(
self._accessKey, self._secretKey, self._endpoint, self._format,
self._signature_version, self._api_version)
def call(self, request):
'''Make API call and translate AWSServiceException to more specific exception'''
try:
log.debug(request)
return_msg = self._client.call(request, self._format)
log.debug(return_msg)
#TODO: set more specific charset code
return return_msg.json
except AwsServiceException as ex:
# Translate general Elastic Beanstalk exception
if misc.string_equal_ignore_case(ex.code,
AwsErrorCode.OptInRequired):
raise OptInRequiredException(ex)
if misc.string_equal_ignore_case(
ex.code, AwsErrorCode.InsufficientPrivileges):
raise InsufficientPrivilegesException(ex)
if misc.string_equal_ignore_case(
ex.code, AwsErrorCode.InvalidParameterValue):
raise InvalidParameterValueException(ex)
if misc.string_equal_ignore_case(ex.code,
AwsErrorCode.MissingParameter):
raise MissingParameterException(ex)
raise
#---------------------------------------
# service calls
def create_application(self, name, description=None):
request = Request()
request.set_operation('CreateApplication')
request.set_app_name(name)
if description is not None:
request.set_description(description)
try:
response = self.call(request)
except AwsServiceException as ex:
if ex.code.lower() == AwsErrorCode.InvalidParameterValue.lower()\
and _re.search(Strings.APP_EXIST_RE, ex.message):
raise AlreadyExistException(ex)
raise
# TODO: take care of too many application exception?
result = response['CreateApplicationResponse']\
['CreateApplicationResult']['Application']
request_id = response['CreateApplicationResponse']\
['ResponseMetadata']['RequestId']
return Response(request_id, ApplicationDescription.from_json(result))
def delete_application(self, name, terminate_env='false'):
request = Request()
request.set_operation('DeleteApplication')
request.set_app_name(name)
request.set_terminate_env(terminate_env)
try:
response = self.call(request)
except AwsServiceException as ex:
if ex.code.lower() == AwsErrorCode.InvalidParameterValue.lower()\
and _re.search(Strings.APP_HAS_RUNNING_ENV, ex.message):
raise ApplicationHasRunningEnvException(ex)
if ex.code.lower() == EBErrorCode.OperationInProgress.lower():
raise OperationInProgressException(ex)
raise
request_id = response['DeleteApplicationResponse']\
['ResponseMetadata']['RequestId']
return Response(request_id)
def create_application_version(self,
application,
version_label,
s3bucket=None,
#.........这里部分代码省略.........
示例6: ElasticBeanstalkClient
class ElasticBeanstalkClient(object):
"""
Web service client for Elastic Beanstalk
"""
_signature_version = AWSSignature.SigV4
_api_version = u"2010-12-01"
_service_name = u"elasticbeanstalk"
def __init__(self, accessKey, secretKey, endpoint, region, result_format="json"):
"""
Constructor
"""
self._accessKey = accessKey
self._secretKey = secretKey
self._endpoint = endpoint
self._format = result_format
self._region = region
self._client = AWSQueryClient(
self._accessKey,
self._secretKey,
self._endpoint,
self._region,
self._service_name,
self._format,
self._signature_version,
self._api_version,
)
def call(self, request):
"""Make API call and translate AWSServiceException to more specific exception"""
try:
log.debug(request)
return_msg = self._client.call(request, self._format)
log.debug(u"Request ID: {0}".format(return_msg.json().values()[0][u"ResponseMetadata"][u"RequestId"]))
# TODO: set more specific charset code
return return_msg.json()
except AwsServiceException as ex:
log.debug(misc.to_unicode(ex))
# Translate general Elastic Beanstalk exception
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.OptInRequired):
raise OptInRequiredException(ex)
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.InsufficientPrivileges):
raise InsufficientPrivilegesException(ex)
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.InvalidParameterValue):
raise InvalidParameterValueException(ex)
if misc.string_equal_ignore_case(ex.code, AwsErrorCode.MissingParameter):
raise MissingParameterException(ex)
raise
# ---------------------------------------
# service calls
def create_application(self, name, description=None):
request = Request()
request.set_operation(u"CreateApplication")
request.set_app_name(name)
if description is not None:
request.set_description(description)
try:
response = self.call(request)
except AwsServiceException as ex:
if ex.code.lower() == AwsErrorCode.InvalidParameterValue.lower() and _re.search(
Strings.APP_EXIST_RE, ex.message
):
raise AlreadyExistException(ex)
raise
# TODO: take care of too many application exception?
result = response[u"CreateApplicationResponse"][u"CreateApplicationResult"][u"Application"]
request_id = response[u"CreateApplicationResponse"][u"ResponseMetadata"][u"RequestId"]
return Response(request_id, ApplicationDescription.from_json(result))
def delete_application(self, name, terminate_env=u"false"):
request = Request()
request.set_operation(u"DeleteApplication")
request.set_app_name(name)
request.set_terminate_env(terminate_env)
try:
response = self.call(request)
except AwsServiceException as ex:
if ex.code.lower() == AwsErrorCode.InvalidParameterValue.lower() and _re.search(
Strings.APP_HAS_RUNNING_ENV, ex.message
):
raise ApplicationHasRunningEnvException(ex)
if ex.code.lower() == EBErrorCode.OperationInProgress.lower():
raise OperationInProgressException(ex)
raise
request_id = response[u"DeleteApplicationResponse"][u"ResponseMetadata"][u"RequestId"]
#.........这里部分代码省略.........