예제 #1
0
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,
    )
예제 #3
0
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_disabled(monkeypatch):
    monkeypatch.delenv("AWS_ACCESS_KEY_ID", raising=False)
    monkeypatch.delenv("AWS_SECRET_ACCESS_KEY", raising=False)
    monkeypatch.delenv("AWS_SESSION_TOKEN", raising=False)
    monkeypatch.delenv("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", raising=False)
    monkeypatch.delenv("AWS_CONTAINER_CREDENTIALS_FULL_URI", raising=False)
    monkeypatch.setenv("AWS_EC2_METADATA_DISABLED", "true")
    creds = Credentials.auto()
    assert creds.candidates == []
    assert creds.is_disabled()
    assert EnvironmentCredentials().is_disabled()
    assert InstanceMetadataCredentials().is_disabled()
    assert ContainerMetadataCredentials().is_disabled()
    monkeypatch.setenv("AWS_EC2_METADATA_DISABLED", "false")
    assert not InstanceMetadataCredentials().is_disabled()
    creds = Credentials.auto()
    assert len(creds.candidates) == 1
    assert not creds.is_disabled()
예제 #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())