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


Python aiobotocore.get_session方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def __init__(self, app, params, timeout=10):
        self.app = app
        self.params = params
        self.timeout = timeout
        self.lambdaFunction = config.get("aws_lambda_chunkread_function")
        self.client = None 
        if "session" not in app:
            app["session"] = get_session()
        
        self.session = app["session"]

        if "lambda_stats" not in app:
            app["lambda_stats"] = {}
        lambda_stats = app["lambda_stats"]
        if self.lambdaFunction not in lambda_stats:
            lambda_stats[self.lambdaFunction] = {"cnt": 0, "inflight": 0, "failed": 0}
        self.funcStats = lambda_stats[self.lambdaFunction] 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:19,代碼來源:awsLambdaClient.py

示例2: testStorUtil

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def testStorUtil(self):

        cors_domain = config.get("cors_domain")
        print(f"cors_domain: [{cors_domain}]")
        bucket = config.get("hsds_unit_test_bucket")
        if not bucket:
            print("No bucket configured, create bucket and export HSDS_UNIT_TEST_BUCKET=<bucket_name> to enable test")
            return

        # we need to setup a asyncio loop to query s3
        loop = asyncio.get_event_loop()
        session = get_session(loop=loop)

        app = {}
        app["session"] = session
        app["bucket_name"] = bucket
        app["loop"] = loop

        loop.run_until_complete(self.stor_util_test(app))

        loop.close() 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:23,代碼來源:storUtilTest.py

示例3: main

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def main():
    if len(sys.argv) == 1 or sys.argv[1] == "-h" or sys.argv[1] == "--help":
        printUsage()
        sys.exit(1)

    obj_id = sys.argv[-1]
    if not isValidUuid(obj_id):
        print("Invalid obj id")

    # we need to setup a asyncio loop to query s3
    loop = asyncio.get_event_loop()
    session = get_session()

    app = {}
    app["session"] = session
    app['bucket_name'] = config.get("bucket_name")
    app["loop"] = loop

    loop.run_until_complete(printS3Obj(app, obj_id))

    loop.close() 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:23,代碼來源:get_s3json.py

示例4: main

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def main():

    if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
        printUsage()
        sys.exit(1)

    # we need to setup a asyncio loop to query s3
    loop = asyncio.get_event_loop()
    #loop.run_until_complete(init(loop))
    session = get_session()

    app = {}
    app['bucket_name'] = config.get("bucket_name")
    app["session"] = session
    app["loop"] = loop

    loop.run_until_complete(deleteAll(app))
    #releaseClient(app)

    loop.close()

    print("done!") 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:24,代碼來源:delete_bucket.py

示例5: test_describe_table

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def test_describe_table(loop, recorder):
    segment = recorder.begin_segment('name')

    req_id = '1234'
    response = {'ResponseMetadata': {'RequestId': req_id, 'HTTPStatusCode': 403}}

    session = aiobotocore.get_session()
    async with session.create_client('dynamodb', region_name='eu-west-2') as client:
        with Stubber(client) as stubber:
            stubber.add_response('describe_table', response, {'TableName': 'mytable'})
            await client.describe_table(TableName='mytable')

    subsegment = segment.subsegments[0]
    assert subsegment.error
    assert subsegment.http['response']['status'] == 403

    aws_meta = subsegment.aws
    assert aws_meta['table_name'] == 'mytable'
    assert aws_meta['request_id'] == req_id
    assert aws_meta['region'] == 'eu-west-2'
    assert aws_meta['operation'] == 'DescribeTable' 
開發者ID:aws,項目名稱:aws-xray-sdk-python,代碼行數:23,代碼來源:test_aiobotocore.py

示例6: test_s3_parameter_capture

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def test_s3_parameter_capture(loop, recorder):
    segment = recorder.begin_segment('name')

    bucket_name = 'mybucket'
    key = 'mykey'
    version_id = 'myversionid'
    response = {'ResponseMetadata': {'RequestId': '1234', 'HTTPStatusCode': 200}}

    session = aiobotocore.get_session()
    async with session.create_client('s3', region_name='eu-west-2') as client:
        with Stubber(client) as stubber:
            stubber.add_response('get_object', response,
                                 {'Bucket': bucket_name, 'Key': key, 'VersionId': version_id})
            await client.get_object(Bucket=bucket_name, Key=key,
                                    VersionId=version_id)

    subsegment = segment.subsegments[0]
    aws_meta = subsegment.aws

    assert aws_meta['bucket_name'] == bucket_name
    assert aws_meta['key'] == key
    assert aws_meta['version_id'] == version_id
    assert aws_meta['operation'] == 'GetObject' 
開發者ID:aws,項目名稱:aws-xray-sdk-python,代碼行數:25,代碼來源:test_aiobotocore.py

示例7: __init__

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def __init__(self, app):
        if "session" not in app:
            session = get_session()
            app["session"] = session
        
        self._app = app 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:8,代碼來源:query_marathon.py

示例8: main

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def main():

    if len(sys.argv) == 1 or len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
        printUsage()


    rootid = sys.argv[1]

    if not isValidUuid(rootid):
        print("Invalid root id!")
        sys.exit(1)

    if not isSchema2Id(rootid):
        print("This tool can only be used with Schema v2 ids")
        sys.exit(1)


    # we need to setup a asyncio loop to query s3
    loop = asyncio.get_event_loop()

    app = {}
    app["bucket_name"] = config.get("bucket_name")
    app["loop"] = loop
    app["objDelete_prefix"] = None
    session = get_session()
    app["session"] = session
    loop.run_until_complete(run_delete(app, rootid))

    loop.close()

    print("done!") 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:33,代碼來源:root_delete.py

示例9: main

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def main():

    if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
        printUsage()


    if len(sys.argv) > 1 and sys.argv[1] == "--update":
        do_update = True
    else:
        do_update = False


    # we need to setup a asyncio loop to query s3
    loop = asyncio.get_event_loop()

    app = {}
    app["bucket_name"] = config.get("bucket_name")
    app["loop"] = loop
    session = get_session()
    app["session"] = session
    loop.run_until_complete(run_scan(app, update=do_update))

    loop.close()

    results = app["bucket_scan"]
    print("root_count:", results["root_count"])
    print("info_count:", results["info_count"])
    print("group_count", results["group_count"])
    print("dataset_count:", results["dataset_count"])
    print("datatype_count", results["datatype_count"])
    print("chunk_count:", results["chunk_count"])
    print('allocated_bytes:', results["allocated_bytes"])
    print("metadata_bytes:", results["metadata_bytes"])
    print("updated_count:", results["updated_count"])

    print("done!") 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:38,代碼來源:bucket_scan.py

示例10: create_client

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def create_client(cls: Any, name: str, context: Dict) -> None:
        logging.getLogger('botocore.vendored.requests.packages.urllib3.connectionpool').setLevel(logging.WARNING)

        if not cls.clients:
            cls.clients = {}
            cls.clients_creation_time = {}
        loop = asyncio.get_event_loop()
        session = aiobotocore.get_session()

        config_base = context.get('options', {}).get('aws_sns_sqs', context.get('options', {}).get('aws', {}))
        aws_config_base = context.get('options', {}).get('aws', {})

        region_name = config_base.get('aws_region_name', config_base.get('region_name')) or \
            aws_config_base.get('aws_region_name', aws_config_base.get('region_name'))
        aws_secret_access_key = config_base.get('aws_secret_access_key', config_base.get('secret_access_key')) or \
            aws_config_base.get('aws_secret_access_key', aws_config_base.get('secret_access_key'))
        aws_access_key_id = config_base.get('aws_access_key_id', config_base.get('access_key_id')) or \
            aws_config_base.get('aws_access_key_id', aws_config_base.get('access_key_id'))
        endpoint_url = config_base.get('aws_endpoint_urls', config_base.get('endpoint_urls', {})).get(name) or \
            config_base.get('aws_{}_endpoint_url'.format(name), config_base.get('{}_endpoint_url'.format(name))) or \
            aws_config_base.get('aws_endpoint_urls', aws_config_base.get('endpoint_urls', {})).get(name) or \
            config_base.get('aws_endpoint_url', config_base.get('endpoint_url')) or \
            aws_config_base.get('aws_endpoint_url', aws_config_base.get('endpoint_url')) or \
            context.get('options', {}).get('aws_endpoint_urls', {}).get(name)

        try:
            if cls.clients_creation_time.get(name) and cls.clients_creation_time[name] + 30 > time.time():
                return
            cls.clients[name] = session.create_client(name, region_name=region_name, aws_secret_access_key=aws_secret_access_key, aws_access_key_id=aws_access_key_id, endpoint_url=endpoint_url)
            cls.clients_creation_time[name] = time.time()
        except (botocore.exceptions.PartialCredentialsError, botocore.exceptions.NoRegionError) as e:
            error_message = str(e)
            logging.getLogger('transport.aws_sns_sqs').warning('Invalid credentials [{}] to AWS ({})'.format(name, error_message))
            raise AWSSNSSQSConnectionException(error_message, log_level=context.get('log_level')) from e 
開發者ID:kalaspuff,項目名稱:tomodachi,代碼行數:36,代碼來源:aws_sns_sqs.py

示例11: go

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def go():
    session = aiobotocore.get_session()
    async with session.create_client('dynamodb', region_name='us-west-2') as client:
        # Create random table name
        table_name = f'aiobotocore-{uuid.uuid4()}'

        print('Requesting table creation...')
        await client.create_table(
            TableName=table_name,
            AttributeDefinitions=[
                {
                    'AttributeName': 'testKey',
                    'AttributeType': 'S'
                },
            ],
            KeySchema=[
                {
                    'AttributeName': 'testKey',
                    'KeyType': 'HASH'
                },
            ],
            ProvisionedThroughput={
                'ReadCapacityUnits': 10,
                'WriteCapacityUnits': 10
            }
        )

        print("Waiting for table to be created...")
        waiter = client.get_waiter('table_exists')
        await waiter.wait(TableName=table_name)
        print(f"Table {table_name} created") 
開發者ID:aio-libs,項目名稱:aiobotocore,代碼行數:33,代碼來源:dynamodb_create_table.py

示例12: go

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def go():
    # Boto should get credentials from ~/.aws/credentials or the environment
    session = aiobotocore.get_session()
    async with session.create_client('sqs', region_name='us-west-2') as client:
        try:
            response = await client.get_queue_url(QueueName=QUEUE_NAME)
        except botocore.exceptions.ClientError as err:
            if err.response['Error']['Code'] == \
                    'AWS.SimpleQueueService.NonExistentQueue':
                print(f"Queue {QUEUE_NAME} does not exist")
                sys.exit(1)
            else:
                raise

        queue_url = response['QueueUrl']

        print('Putting messages on the queue')

        msg_no = 1
        while True:
            try:
                msg_body = f'Message #{msg_no}'
                await client.send_message(
                    QueueUrl=queue_url,
                    MessageBody=msg_body
                )
                msg_no += 1

                print(f'Pushed "{msg_body}" to queue')

                await asyncio.sleep(random.randint(1, 4))
            except KeyboardInterrupt:
                break

        print('Finished') 
開發者ID:aio-libs,項目名稱:aiobotocore,代碼行數:37,代碼來源:sqs_queue_producer.py

示例13: go

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def go():

    bucket = 'dataintake'
    filename = 'dummy.bin'
    folder = 'aiobotocore'
    key = f'{folder}/{filename}'

    session = aiobotocore.get_session()
    async with session.create_client(
            's3', region_name='us-west-2',
            aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
            aws_access_key_id=AWS_ACCESS_KEY_ID) as client:
        # upload object to amazon s3
        data = b'\x01' * 1024
        resp = await client.put_object(Bucket=bucket,
                                       Key=key,
                                       Body=data)
        print(resp)

        # getting s3 object properties of file we just uploaded
        resp = await client.get_object_acl(Bucket=bucket, Key=key)
        print(resp)

        # delete object from s3
        resp = await client.delete_object(Bucket=bucket, Key=key)
        print(resp) 
開發者ID:aio-libs,項目名稱:aiobotocore,代碼行數:28,代碼來源:simple.py

示例14: go

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def go():
    # Boto should get credentials from ~/.aws/credentials or the environment
    session = aiobotocore.get_session()
    async with session.create_client('sqs', region_name='us-west-2') as client:
        try:
            response = await client.get_queue_url(QueueName=QUEUE_NAME)
        except botocore.exceptions.ClientError as err:
            if err.response['Error']['Code'] == \
                    'AWS.SimpleQueueService.NonExistentQueue':
                print("Queue {0} does not exist".format(QUEUE_NAME))
                sys.exit(1)
            else:
                raise

        queue_url = response['QueueUrl']

        print('Pulling messages off the queue')

        while True:
            try:
                # This loop wont spin really fast as there is
                # essentially a sleep in the receive_message call
                response = await client.receive_message(
                    QueueUrl=queue_url,
                    WaitTimeSeconds=2,
                )

                if 'Messages' in response:
                    for msg in response['Messages']:
                        print(f'Got msg "{msg["Body"]}"')
                        # Need to remove msg from queue or else it'll reappear
                        await client.delete_message(
                            QueueUrl=queue_url,
                            ReceiptHandle=msg['ReceiptHandle']
                        )
                else:
                    print('No messages in queue')
            except KeyboardInterrupt:
                break

        print('Finished') 
開發者ID:aio-libs,項目名稱:aiobotocore,代碼行數:43,代碼來源:sqs_queue_consumer.py

示例15: test_list_parameter_counting

# 需要導入模塊: import aiobotocore [as 別名]
# 或者: from aiobotocore import get_session [as 別名]
def test_list_parameter_counting(loop, recorder):
    """
    Test special parameters that have shape of list are recorded
    as count based on `para_whitelist.json`
    """
    segment = recorder.begin_segment('name')

    queue_urls = ['url1', 'url2']
    queue_name_prefix = 'url'
    response = {
        'QueueUrls': queue_urls,
        'ResponseMetadata': {
            'RequestId': '1234',
            'HTTPStatusCode': 200,
        }
    }

    session = aiobotocore.get_session()
    async with session.create_client('sqs', region_name='eu-west-2') as client:
        with Stubber(client) as stubber:
            stubber.add_response('list_queues', response, {'QueueNamePrefix': queue_name_prefix})
            await client.list_queues(QueueNamePrefix='url')

    subsegment = segment.subsegments[0]
    assert subsegment.http['response']['status'] == 200

    aws_meta = subsegment.aws
    assert aws_meta['queue_count'] == len(queue_urls)
    # all whitelisted input parameters will be converted to snake case
    # unless there is an explicit 'rename_to' attribute in json key
    assert aws_meta['queue_name_prefix'] == queue_name_prefix 
開發者ID:aws,項目名稱:aws-xray-sdk-python,代碼行數:33,代碼來源:test_aiobotocore.py


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