當前位置: 首頁>>代碼示例>>Python>>正文


Python boto3.DEFAULT_SESSION屬性代碼示例

本文整理匯總了Python中boto3.DEFAULT_SESSION屬性的典型用法代碼示例。如果您正苦於以下問題:Python boto3.DEFAULT_SESSION屬性的具體用法?Python boto3.DEFAULT_SESSION怎麽用?Python boto3.DEFAULT_SESSION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在boto3的用法示例。


在下文中一共展示了boto3.DEFAULT_SESSION屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_aws_region

# 需要導入模塊: import boto3 [as 別名]
# 或者: from boto3 import DEFAULT_SESSION [as 別名]
def get_aws_region(_default='us-east-1'):
    # Try to use the explicit KINESIS_REGION setting
    region = get('KINESIS_REGION', '')
    if region:
        return region
    # Try to import boto3 to get the region name
    try:
        import boto3
    except ImportError:
        # Can't import boto3, so fallback to the AWS_DEFAULT_REGION environment variable, then finally, us-east-1
        return os.environ.get('AWS_DEFAULT_REGION', _default)
    # Use the region for boto3's default session
    if boto3.DEFAULT_SESSION is not None:
        region = boto3.DEFAULT_SESSION.region_name
        if region:
            return region
    # Finally, make a new session and use it's region
    region = boto3.session.Session().region_name
    if region:
        return region
    # Finally, return the default
    return _default 
開發者ID:thelabnyc,項目名稱:django-logpipe,代碼行數:24,代碼來源:settings.py

示例2: test_athena_query_cancelled

# 需要導入模塊: import boto3 [as 別名]
# 或者: from boto3 import DEFAULT_SESSION [as 別名]
def test_athena_query_cancelled(glue_database):
    session = boto3.DEFAULT_SESSION
    query_execution_id = wr.athena.start_query_execution(
        sql=get_query_long(), database=glue_database, boto3_session=session
    )
    wr.athena.stop_query_execution(query_execution_id=query_execution_id, boto3_session=session)
    with pytest.raises(wr.exceptions.QueryCancelled):
        assert wr.athena.wait_query(query_execution_id=query_execution_id) 
開發者ID:awslabs,項目名稱:aws-data-wrangler,代碼行數:10,代碼來源:test_athena.py

示例3: test_parquet

# 需要導入模塊: import boto3 [as 別名]
# 或者: from boto3 import DEFAULT_SESSION [as 別名]
def test_parquet(path):
    df_file = pd.DataFrame({"id": [1, 2, 3]})
    path_file = f"{path}test_parquet_file.parquet"
    df_dataset = pd.DataFrame({"id": [1, 2, 3], "partition": ["A", "A", "B"]})
    df_dataset["partition"] = df_dataset["partition"].astype("category")
    path_dataset = f"{path}test_parquet_dataset"
    with pytest.raises(wr.exceptions.InvalidArgumentCombination):
        wr.s3.to_parquet(df=df_file, path=path_file, mode="append")
    with pytest.raises(wr.exceptions.InvalidCompression):
        wr.s3.to_parquet(df=df_file, path=path_file, compression="WRONG")
    with pytest.raises(wr.exceptions.InvalidArgumentCombination):
        wr.s3.to_parquet(df=df_dataset, path=path_dataset, partition_cols=["col2"])
    with pytest.raises(wr.exceptions.InvalidArgumentCombination):
        wr.s3.to_parquet(df=df_dataset, path=path_dataset, description="foo")
    with pytest.raises(wr.exceptions.InvalidArgumentValue):
        wr.s3.to_parquet(df=df_dataset, path=path_dataset, partition_cols=["col2"], dataset=True, mode="WRONG")
    paths = wr.s3.to_parquet(df=df_file, path=path_file)["paths"]
    wr.s3.wait_objects_exist(paths=paths)
    assert len(wr.s3.read_parquet(path=path_file, use_threads=True, boto3_session=None).index) == 3
    assert len(wr.s3.read_parquet(path=[path_file], use_threads=False, boto3_session=boto3.DEFAULT_SESSION).index) == 3
    paths = wr.s3.to_parquet(df=df_dataset, path=path_dataset, dataset=True)["paths"]
    wr.s3.wait_objects_exist(paths=paths)
    assert len(wr.s3.read_parquet(path=paths, dataset=True).index) == 3
    assert len(wr.s3.read_parquet(path=path_dataset, use_threads=True, boto3_session=boto3.DEFAULT_SESSION).index) == 3
    dataset_paths = wr.s3.to_parquet(
        df=df_dataset, path=path_dataset, dataset=True, partition_cols=["partition"], mode="overwrite"
    )["paths"]
    wr.s3.wait_objects_exist(paths=dataset_paths)
    assert len(wr.s3.read_parquet(path=path_dataset, use_threads=True, boto3_session=None).index) == 3
    assert len(wr.s3.read_parquet(path=dataset_paths, use_threads=True).index) == 3
    assert len(wr.s3.read_parquet(path=path_dataset, dataset=True, use_threads=True).index) == 3
    wr.s3.to_parquet(df=df_dataset, path=path_dataset, dataset=True, partition_cols=["partition"], mode="overwrite")
    wr.s3.to_parquet(
        df=df_dataset, path=path_dataset, dataset=True, partition_cols=["partition"], mode="overwrite_partitions"
    ) 
開發者ID:awslabs,項目名稱:aws-data-wrangler,代碼行數:37,代碼來源:test_s3.py

示例4: test_s3_get_bucket_region

# 需要導入模塊: import boto3 [as 別名]
# 或者: from boto3 import DEFAULT_SESSION [as 別名]
def test_s3_get_bucket_region(bucket, region):
    assert wr.s3.get_bucket_region(bucket=bucket) == region
    assert wr.s3.get_bucket_region(bucket=bucket, boto3_session=boto3.DEFAULT_SESSION) == region 
開發者ID:awslabs,項目名稱:aws-data-wrangler,代碼行數:5,代碼來源:test_s3.py

示例5: _initialize

# 需要導入模塊: import boto3 [as 別名]
# 或者: from boto3 import DEFAULT_SESSION [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


注:本文中的boto3.DEFAULT_SESSION屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。