当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.BotoCoreError方法代码示例

本文整理汇总了Python中botocore.exceptions.BotoCoreError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.BotoCoreError方法的具体用法?Python exceptions.BotoCoreError怎么用?Python exceptions.BotoCoreError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在botocore.exceptions的用法示例。


在下文中一共展示了exceptions.BotoCoreError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _load

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def _load(self, zip_file_dir: str, market_definition: dict) -> None:
        # note this will block the main handler queue during upload
        # todo create background worker instead?
        event_type_id = (
            market_definition.get("eventTypeId", 0) if market_definition else "7"
        )
        try:
            self.transfer.upload_file(
                filename=zip_file_dir,
                bucket=self._bucket,
                key=os.path.join(
                    self._data_type,
                    "streaming",
                    event_type_id,
                    os.path.basename(zip_file_dir),
                ),
                extra_args={
                    "Metadata": self._create_metadata(market_definition)
                    if market_definition
                    else {}
                },
            )
            logger.info("%s successfully loaded to s3" % zip_file_dir)
        except (BotoCoreError, Exception) as e:
            logger.error("Error loading to s3: %s" % e) 
开发者ID:liampauling,项目名称:flumine,代码行数:27,代码来源:marketrecorder.py

示例2: get_images

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_images(self, name_pattern):
        """
        Return list of AMIs matching the given name_pattern

        :param name_pattern: str: AMI name pattern
        :return: list(dict)
        :raise CfnSphereException:
        """
        filters = [
            {'Name': 'name', 'Values': [name_pattern]},
            {'Name': 'is-public', 'Values': ['false']},
            {'Name': 'state', 'Values': ['available']},
            {'Name': 'root-device-type', 'Values': ['ebs']}
        ]

        try:
            response = self.client.describe_images(ExecutableUsers=["self"], Filters=filters)
        except (BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e)

        if not response['Images']:
            raise CfnSphereException("Could not find any private and available Taupage AMI")

        return response['Images'] 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:26,代码来源:ec2.py

示例3: create_stack

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def create_stack(self, stack):
        self.logger.debug("Creating stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:
            stack_parameters_string = get_pretty_parameters_string(stack)

            self.logger.info(
                "Creating stack {0} ({1}) with parameters:\n{2}".format(stack.name,
                                                                        stack.template.name,
                                                                        stack_parameters_string))
            self._create_stack(stack)

            self.wait_for_stack_action_to_complete(stack.name, "create", stack.timeout)

            stack_outputs = get_pretty_stack_outputs(self.get_stack_outputs(stack))
            if stack_outputs:
                self.logger.info("Create completed for {0} with outputs: \n{1}".format(stack.name, stack_outputs))
            else:
                self.logger.info("Create completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException("Could not create {0}: {1}".format(stack.name, e)) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:24,代码来源:cfn.py

示例4: delete_stack

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def delete_stack(self, stack):
        self.logger.debug("Deleting stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:
            self.logger.info("Deleting stack {0}".format(stack.name))
            self._delete_stack(stack)

            try:
                self.wait_for_stack_action_to_complete(stack.name, "delete", stack.timeout)
            except CfnSphereBotoError as e:
                if self.is_boto_stack_does_not_exist_exception(e.boto_exception):
                    pass
                else:
                    raise

            self.logger.info("Deletion completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException("Could not delete {0}: {1}".format(stack.name, e)) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:21,代码来源:cfn.py

示例5: get_meta_table

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_meta_table(self, table_name: str, refresh: bool = False):
        """
        Returns a MetaTable
        """
        if table_name not in self._tables or refresh:
            operation_kwargs = {
                TABLE_NAME: table_name
            }
            try:
                data = self.dispatch(DESCRIBE_TABLE, operation_kwargs)
                self._tables[table_name] = MetaTable(data.get(TABLE_KEY))
            except BotoCoreError as e:
                raise TableError("Unable to describe table: {}".format(e), e)
            except ClientError as e:
                if 'ResourceNotFound' in e.response['Error']['Code']:
                    raise TableDoesNotExist(e.response['Error']['Message'])
                else:
                    raise
        return self._tables[table_name] 
开发者ID:pynamodb,项目名称:PynamoDB,代码行数:21,代码来源:base.py

示例6: _process_md5

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def _process_md5(md5: str) -> bool:
    """Download the given file from CarbonBlack and upload to S3, returning True if successful."""
    try:
        binary = CARBON_BLACK.select(Binary, md5)
        _upload_to_s3(binary)
        return True
    except zipfile.BadZipFile:
        LOGGER.exception('[BadZipFile] Error downloading %s', md5)
        LOGGER.info('This md5 is invalid and will not retried')
        return False
    except (BotoCoreError, ServerError):
        LOGGER.exception('Error downloading %s', md5)
        LOGGER.error(
            'A temporary error was encountered during downloading. This md5 will be '
            'retried at a later time.'
        )
        raise
    except ObjectNotFoundError:
        LOGGER.exception('Error downloading %s', md5)
        LOGGER.info(
            'This may be caused due to a race condition where the requested binary is not yet '
            'available for download from the server. This binary will be retried at a later time.'
        )
        raise 
开发者ID:airbnb,项目名称:binaryalert,代码行数:26,代码来源:main.py

示例7: test_remove_bad_client

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def test_remove_bad_client():
    test = KMSMasterKeyProvider()
    test.add_regional_client("us-fakey-12")

    with pytest.raises(BotoCoreError):
        test._regional_clients["us-fakey-12"].list_keys()

    assert not test._regional_clients 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:10,代码来源:test_i_aws_encrytion_sdk_client.py

示例8: get_contents_from_url

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_contents_from_url(self, url):
        try:
            (_, bucket_name, key_name) = self._parse_url(url)
            s3_object = self.s3.Object(bucket_name, key_name)
            return s3_object.get(ResponseContentEncoding='utf-8')["Body"].read().decode('utf-8')
        except (Boto3Error, BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:s3.py

示例9: get_stacks

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_stacks(self):
        """
        Get all stacks
        :return: List(boto3.resources.factory.cloudformation.Stack)
        :raise CfnSphereBotoError:
        """
        try:
            return list(self.resource.stacks.all())
        except (BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:12,代码来源:cfn.py

示例10: get_stack_description

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_stack_description(self, stack_name):
        """
        Get a stacks descriptions
        :param stack_name: string
        :return dict
        :raise CfnSphereBotoError:
        """
        try:
            return self.client.describe_stacks(StackName=stack_name)["Stacks"][0]
        except (BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:13,代码来源:cfn.py

示例11: get_stack_descriptions

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_stack_descriptions(self):
        """
        Get all stacks stack descriptions
        :return List(dict)
        :raise CfnSphereBotoError:
        """
        try:
            stacks = []
            for page in self.client.get_paginator('describe_stacks').paginate():
                stacks += page["Stacks"]
            return stacks
        except (BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:15,代码来源:cfn.py

示例12: get_stack_events

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_stack_events(self, stack_name):
        """
        Get recent stack events for a given stack_name
        :param stack_name: str
        :return: list(dict)
        """
        try:
            paginator = self.client.get_paginator('describe_stack_events')
            pages = paginator.paginate(StackName=stack_name, PaginationConfig={'MaxItems': 100})
            return next(iter(pages))["StackEvents"]
        except (BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:14,代码来源:cfn.py

示例13: update_stack

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def update_stack(self, stack):
        self.logger.debug("Updating stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:
            stack_parameters_string = get_pretty_parameters_string(stack)

            try:
                self._update_stack(stack)
            except ClientError as e:

                if self.is_boto_no_update_required_exception(e):
                    self.logger.info("Stack {0} does not need an update".format(stack.name))
                    return
                else:
                    self.logger.info(
                        "Updating stack {0} ({1}) with parameters:\n{2}".format(stack.name,
                                                                                stack.template.name,
                                                                                stack_parameters_string))
                    raise

            self.logger.info(
                "Updating stack {0} ({1}) with parameters:\n{2}".format(stack.name,
                                                                        stack.template.name,
                                                                        stack_parameters_string))

            self.wait_for_stack_action_to_complete(stack.name, "update", stack.timeout)

            stack_outputs = get_pretty_stack_outputs(self.get_stack_outputs(stack))
            if stack_outputs:
                self.logger.info("Update completed for {0} with outputs: \n{1}".format(stack.name, stack_outputs))
            else:
                self.logger.info("Update completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException("Could not update {0}: {1}".format(stack.name, e)) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:37,代码来源:cfn.py

示例14: validate_template

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def validate_template(self, template):
        """
        Validate template
        :param template: CloudFormationTemplate
        :return: boolean (true if valid)
        """
        try:
            self.client.validate_template(TemplateBody=template.get_template_json())
            return True
        except (BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:13,代码来源:cfn.py

示例15: get_session_with_arn

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import BotoCoreError [as 别名]
def get_session_with_arn(role_arn, session_name, base_session):
    """
    Returns a boto3.session.Session that assumed role_arn from base_session.

    base_session is the session used to assume the role;
        it must have permissions to assume the role.
    By default, base_session is the caller's regular boto3 session.
    """
    if not base_session:
        base_session = boto3.Session()

    if not session_name:
        session_name = "aws_common_utils"

    session_name = handle_session_name_length(session_name)
    client = base_session.client("sts")

    try:
        response = client.assume_role(RoleArn=role_arn, RoleSessionName=session_name)

        access_key = response["Credentials"]["AccessKeyId"]
        secret = response["Credentials"]["SecretAccessKey"]
        session_token = response["Credentials"]["SessionToken"]

        return boto3.Session(
            aws_access_key_id=access_key,
            aws_secret_access_key=secret,
            aws_session_token=session_token,
        )
    except (BotoCoreError, ClientError) as e:
        logging.error(
            "get_session_with_arn() failed trying to assume %s \
                       due to clienterror or botocore error",
            role_arn,
        )
        logging.error(str(e))
        raise e 
开发者ID:Snapchat,项目名称:aws-support-tickets-aggregator,代码行数:39,代码来源:aws_common_utils_layer.py


注:本文中的botocore.exceptions.BotoCoreError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。