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


Python botocore.config方法代码示例

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


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

示例1: _s3_conn

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _s3_conn(context):
    region = CONF.s3_region
    ec2_creds = clients.keystone(context).ec2.list(context.user_id)

    # Here we a) disable user's default config to let ec2api works independetly
    # of user's local settings;
    # b) specify region to be used by botocore;
    # c) do not change standard botocore keys to get these settings
    # from environment
    connection_data = {
        'config_file': (None, 'AWS_CONFIG_FILE', None, None),
        'region': ('region', 'AWS_DEFAULT_REGION', region, None),
    }
    session = botocore.session.get_session(connection_data)
    return session.create_client(
        's3', region_name=region, endpoint_url=CONF.s3_url,
        aws_access_key_id=ec2_creds[0].access,
        aws_secret_access_key=ec2_creds[0].secret,
        config=botocore.config.Config(signature_version='s3v4')) 
开发者ID:openstack,项目名称:ec2-api,代码行数:21,代码来源:image.py

示例2: _logs_init

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _logs_init(sagemaker_session, description, job):
    """Placeholder docstring"""
    if job == "Training":
        instance_count = description["ResourceConfig"]["InstanceCount"]
    elif job == "Transform":
        instance_count = description["TransformResources"]["InstanceCount"]
    elif job == "Processing":
        instance_count = description["ProcessingResources"]["ClusterConfig"]["InstanceCount"]
    elif job == "AutoML":
        instance_count = 0

    stream_names = []  # The list of log streams
    positions = {}  # The current position in each stream, map of stream name -> position

    # Increase retries allowed (from default of 4), as we don't want waiting for a training job
    # to be interrupted by a transient exception.
    config = botocore.config.Config(retries={"max_attempts": 15})
    client = sagemaker_session.boto_session.client("logs", config=config)
    log_group = "/aws/sagemaker/" + job + "Jobs"

    dot = False

    color_wrap = sagemaker.logs.ColorWrap()

    return instance_count, stream_names, positions, client, log_group, dot, color_wrap 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:27,代码来源:session.py

示例3: terminate_node

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def terminate_node(self, node_id):
        node = self._get_cached_node(node_id)
        if self.cache_stopped_nodes:
            if node.spot_instance_request_id:
                logger.info(
                    "AWSNodeProvider: terminating node {} (spot nodes cannot "
                    "be stopped, only terminated)".format(node_id))
                node.terminate()
            else:
                logger.info(
                    "AWSNodeProvider: stopping node {}. To terminate nodes "
                    "on stop, set 'cache_stopped_nodes: False' in the "
                    "provider config.".format(node_id))
                node.stop()
        else:
            node.terminate()

        self.tag_cache.pop(node_id, None)
        self.tag_cache_pending.pop(node_id, None) 
开发者ID:ray-project,项目名称:ray,代码行数:21,代码来源:node_provider.py

示例4: bootstrap_aws

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def bootstrap_aws(config):
    # The head node needs to have an IAM role that allows it to create further
    # EC2 instances.
    config = _configure_iam_role(config)

    # Configure SSH access, using an existing key pair if possible.
    config = _configure_key_pair(config)

    # Pick a reasonable subnet if not specified by the user.
    config = _configure_subnet(config)

    # Cluster workers should be in a security group that permits traffic within
    # the group, and also SSH access from outside.
    config = _configure_security_group(config)

    # Provide a helpful message for missing AMI.
    _check_ami(config)

    return config 
开发者ID:ray-project,项目名称:ray,代码行数:21,代码来源:config.py

示例5: get_client_with_retries

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def get_client_with_retries(service_name, methods, context=None, region=None, session=None, wait_strategy=None,
                            method_suffix=DEFAULT_SUFFIX, logger=None):
    args = {
        "service_name": service_name,
    }

    if region is not None:
        args["region_name"] = region

    user_agent = os.getenv(ENV_USER_AGENT, None)
    if user_agent is not None:
        session_config = botocore.config.Config(user_agent=user_agent)
        args["config"] = session_config

    if session is not None:
        aws_session = session
    else:
        aws_session = services.get_session()

    result = aws_session.client(**args)

    # get strategy for the service
    service_retry_strategy = get_default_retry_strategy(context=context, service=service_name,
                                                        wait_strategy=wait_strategy, logger=logger)

    # add a new method to the client instance that wraps the original method with service specific retry logic
    for method in methods:
        make_method_with_retries(boto_client_or_resource=result,
                                 name=method,
                                 service_retry_strategy=service_retry_strategy,
                                 method_suffix=method_suffix)
    return result 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:34,代码来源:__init__.py

示例6: _get_botocore_config

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _get_botocore_config():
    return botocore.config.Config(
        retries={
            'max_attempts': 8,
        },
    ) 
开发者ID:lyft,项目名称:cartography,代码行数:8,代码来源:elasticsearch.py

示例7: sync

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def sync(neo4j_session, boto3_session, aws_account_id, update_tag):
    for region in es_regions:
        logger.info("Syncing Elasticsearch Service for region '%s' in account '%s'.", region, aws_account_id)
        client = boto3_session.client('es', region_name=region, config=_get_botocore_config())
        data = _get_es_domains(client)
        _load_es_domains(neo4j_session, data, aws_account_id, update_tag)

    cleanup(neo4j_session, update_tag, aws_account_id) 
开发者ID:lyft,项目名称:cartography,代码行数:10,代码来源:elasticsearch.py

示例8: _process_config

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _process_config(self):
        """Traverses the config and adds master keys and regional clients as needed."""
        self._user_agent_adding_config = botocore.config.Config(user_agent_extra=USER_AGENT_SUFFIX)

        if self.config.region_names:
            self.add_regional_clients_from_list(self.config.region_names)
            self.default_region = self.config.region_names[0]
        else:
            self.default_region = self.config.botocore_session.get_config_variable("region")
            if self.default_region is not None:
                self.add_regional_client(self.default_region)

        if self.config.key_ids:
            self.add_master_keys_from_list(self.config.key_ids) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:16,代码来源:kms.py

示例9: add_regional_client

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def add_regional_client(self, region_name):
        """Adds a regional client for the specified region if it does not already exist.

        :param str region_name: AWS Region ID (ex: us-east-1)
        """
        if region_name not in self._regional_clients:
            session = boto3.session.Session(botocore_session=self.config.botocore_session)
            client = session.client("kms", region_name=region_name, config=self._user_agent_adding_config)
            self._register_client(client, region_name)
            self._regional_clients[region_name] = client 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:12,代码来源:kms.py

示例10: _new_master_key

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _new_master_key(self, key_id):
        """Returns a KMSMasterKey for the specified key_id.

        :param bytes key_id: KMS CMK ID
        :returns: KMS Master Key based on key_id
        :rtype: aws_encryption_sdk.key_providers.kms.KMSMasterKey
        :raises InvalidKeyIdError: if key_id is not a valid KMS CMK ID to which this key provider has access
        """
        _key_id = to_str(key_id)  # KMS client requires str, not bytes
        return KMSMasterKey(config=KMSMasterKeyConfig(key_id=key_id, client=self._client(_key_id))) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:12,代码来源:kms.py

示例11: client_default

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def client_default(self):
        """Create a client if one was not provided."""
        try:
            region_name = _region_from_key_id(to_str(self.key_id))
            kwargs = dict(region_name=region_name)
        except UnknownRegionError:
            kwargs = {}
        botocore_config = botocore.config.Config(user_agent_extra=USER_AGENT_SUFFIX)
        return boto3.session.Session(**kwargs).client("kms", config=botocore_config) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:11,代码来源:kms.py

示例12: _generate_data_key

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _generate_data_key(self, algorithm, encryption_context=None):
        """Generates data key and returns plaintext and ciphertext of key.

        :param algorithm: Algorithm on which to base data key
        :type algorithm: aws_encryption_sdk.identifiers.Algorithm
        :param dict encryption_context: Encryption context to pass to KMS
        :returns: Generated data key
        :rtype: aws_encryption_sdk.structures.DataKey
        """
        kms_params = {"KeyId": self._key_id, "NumberOfBytes": algorithm.kdf_input_len}
        if encryption_context is not None:
            kms_params["EncryptionContext"] = encryption_context
        if self.config.grant_tokens:
            kms_params["GrantTokens"] = self.config.grant_tokens
        # Catch any boto3 errors and normalize to expected EncryptKeyError
        try:
            response = self.config.client.generate_data_key(**kms_params)
            plaintext = response["Plaintext"]
            ciphertext = response["CiphertextBlob"]
            key_id = response["KeyId"]
        except (ClientError, KeyError):
            error_message = "Master Key {key_id} unable to generate data key".format(key_id=self._key_id)
            _LOGGER.exception(error_message)
            raise GenerateKeyError(error_message)
        return DataKey(
            key_provider=MasterKeyInfo(provider_id=self.provider_id, key_info=key_id),
            data_key=plaintext,
            encrypted_data_key=ciphertext,
        ) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:31,代码来源:kms.py

示例13: _decrypt_data_key

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context=None):
        """Decrypts an encrypted data key and returns the plaintext.

        :param data_key: Encrypted data key
        :type data_key: aws_encryption_sdk.structures.EncryptedDataKey
        :type algorithm: `aws_encryption_sdk.identifiers.Algorithm` (not used for KMS)
        :param dict encryption_context: Encryption context to use in decryption
        :returns: Decrypted data key
        :rtype: aws_encryption_sdk.structures.DataKey
        :raises DecryptKeyError: if Master Key is unable to decrypt data key
        """
        kms_params = {"CiphertextBlob": encrypted_data_key.encrypted_data_key}
        if encryption_context:
            kms_params["EncryptionContext"] = encryption_context
        if self.config.grant_tokens:
            kms_params["GrantTokens"] = self.config.grant_tokens
        # Catch any boto3 errors and normalize to expected DecryptKeyError
        try:
            response = self.config.client.decrypt(**kms_params)
            plaintext = response["Plaintext"]
        except (ClientError, KeyError):
            error_message = "Master Key {key_id} unable to decrypt data key".format(key_id=self._key_id)
            _LOGGER.exception(error_message)
            raise DecryptKeyError(error_message)
        return DataKey(
            key_provider=self.key_provider, data_key=plaintext, encrypted_data_key=encrypted_data_key.encrypted_data_key
        ) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:29,代码来源:kms.py

示例14: __init__

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def __init__(
        self,
        boto_session=None,
        sagemaker_client=None,
        sagemaker_runtime_client=None,
        default_bucket=None,
    ):
        """Initialize a SageMaker ``Session``.

        Args:
            boto_session (boto3.session.Session): The underlying Boto3 session which AWS service
                calls are delegated to (default: None). If not provided, one is created with
                default AWS configuration chain.
            sagemaker_client (boto3.SageMaker.Client): Client which makes Amazon SageMaker service
                calls other than ``InvokeEndpoint`` (default: None). Estimators created using this
                ``Session`` use this client. If not provided, one will be created using this
                instance's ``boto_session``.
            sagemaker_runtime_client (boto3.SageMakerRuntime.Client): Client which makes
                ``InvokeEndpoint`` calls to Amazon SageMaker (default: None). Predictors created
                using this ``Session`` use this client. If not provided, one will be created using
                this instance's ``boto_session``.
            default_bucket (str): The default Amazon S3 bucket to be used by this session.
                This will be created the next time an Amazon S3 bucket is needed (by calling
                :func:`default_bucket`).
                If not provided, a default bucket will be created based on the following format:
                "sagemaker-{region}-{aws-account-id}".
                Example: "sagemaker-my-custom-bucket".

        """
        self._default_bucket = None
        self._default_bucket_name_override = default_bucket
        self.s3_resource = None
        self.s3_client = None
        self.config = None

        self._initialize(
            boto_session=boto_session,
            sagemaker_client=sagemaker_client,
            sagemaker_runtime_client=sagemaker_runtime_client,
        ) 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:42,代码来源:session.py

示例15: _initialize

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import config [as 别名]
def _initialize(self, boto_session, sagemaker_client, sagemaker_runtime_client):
        """Initialize this SageMaker Session.

        Creates or uses a boto_session, sagemaker_client and sagemaker_runtime_client.
        Sets the region_name.
        """
        self.boto_session = boto_session or boto3.DEFAULT_SESSION or boto3.Session()

        self._region_name = self.boto_session.region_name
        if self._region_name is None:
            raise ValueError(
                "Must setup local AWS configuration with a region supported by SageMaker."
            )

        self.sagemaker_client = sagemaker_client or self.boto_session.client("sagemaker")
        prepend_user_agent(self.sagemaker_client)

        if sagemaker_runtime_client is not None:
            self.sagemaker_runtime_client = sagemaker_runtime_client
        else:
            config = botocore.config.Config(read_timeout=80)
            self.sagemaker_runtime_client = self.boto_session.client(
                "runtime.sagemaker", config=config
            )

        prepend_user_agent(self.sagemaker_runtime_client)

        self.local_mode = False 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:30,代码来源:session.py


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