async def inner():
    async with ClientSession() as session:
        client = Client(AIOHTTP(session), Credentials.auto(), REGION_NAME)
        items = [
            item
            async for item in client.query(TABLE_NAME, Key(KEY_FIELD).eq(KEY_VALUE))
        ]
示例#2
0
def client(http: HTTP, endpoint: URL, region: str) -> Client:
    yield Client(
        http,
        Credentials.auto(),
        region,
        endpoint,
    )
async def inner():
    async with AsyncClient() as http_client:
        client = Client(HTTPX(http_client), Credentials.auto(), REGION_NAME)
        items = [
            item async for item in client.query(TABLE_NAME,
                                                Key(KEY_FIELD).eq(KEY_VALUE))
        ]
示例#4
0
async def test_no_credentials(http: HTTP, endpoint: URL, region: str):
    client = Client(
        http,
        ChainCredentials([]),
        region,
        endpoint,
        throttle_config=ExponentialBackoffThrottling(time_limit_secs=1),
    )
    with pytest.raises(NoCredentialsFound):
        await client.get_item("no-table", {"key": "no-key"})
示例#5
0
async def example():
    async with ClientSession() as session:
        client = Client(AIOHTTP(session), Credentials.auto(), "us-east-1")

        table = client.table("my-table")

        # Create table if it doesn't exist
        if not await table.exists():
            await table.create(
                Throughput(read=10, write=10),
                KeySchema(hash_key=KeySpec("key", KeyType.string)),
            )

        # Create or override an item
        await table.put_item({"key": "my-item", "value": 1})
        # Get an item
        item = await table.get_item({"key": "my-item"})
        print(item)
        # Update an item, if it exists.
        await table.update_item({"key": "my-item"},
                                F("value").add(1),
                                condition=F("key").exists())