Beispiel #1
0
async def aio_aws_client(
    service_name: str, *args, **kwargs
) -> aiobotocore.client.AioBaseClient:
    """
    Yield an asyncio AWS client with an option to provide a client-specific config; this is a
    thin wrapper on ``aiobotocore.get_session().create_client()`` and the additional
    kwargs as passed through to ``session.create_client(**kwargs)``.

    It is possible to pass through additional args and kwargs
    including `config: aiobotocore.config.AioConfig`
    (the default is :py:func:`aio_aws_default_config`)

    .. code-block::

        s3_endpoint = "http://localhost:5555"
        client_config = botocore.client.Config(
            read_timeout=120,
            max_pool_connections=50,
        )
        async with aio_aws_client(
            "s3", endpoint_url=s3_endpoint, config=client_config
        ) as client:
            assert "aiobotocore.client.S3" in str(client)
            assert isinstance(client, aiobotocore.client.AioBaseClient)

    :param service_name: an AWS service for a client, like "s3", try
            :py:meth:`session.get_available_services()`
    :yield: aiobotocore.client.AioBaseClient

    .. seealso::
        - https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html
    """
    session = aio_aws_session()
    async with session.create_client(service_name, *args, **kwargs) as client:
        yield client
Beispiel #2
0
 async def __aenter__(self) -> BlobstoreSession:
     await self._sem.acquire()
     session = aiobotocore.session.AioSession()
     self._s3_client = await self._exit_stack.enter_async_context(
         session.create_client(
             "s3",
             region_name=self._region,
             config=_aio_boto_config,
             endpoint_url=self._endpoint,
         ))
     return self
Beispiel #3
0
def aiobotocore_client(service, tracer):
    """Helper function that creates a new aiobotocore client so that
    it is closed at the end of the context manager.
    """
    session = aiobotocore.session.get_session()
    endpoint = LOCALSTACK_ENDPOINT_URL[service]
    client = session.create_client(service,
                                   region_name='us-west-2',
                                   endpoint_url=endpoint)
    Pin.override(client, tracer=tracer)
    try:
        yield client
    finally:
        client.close()
async def test_kinesis_stream_json_parser(exit_stack: AsyncExitStack):
    # unfortunately moto doesn't support kinesis register_stream_consumer +
    # subscribe_to_shard yet
    stream_name = "my_stream"
    stream_arn = consumer_arn = None
    consumer_name = 'consumer'

    session = aiobotocore.session.AioSession()

    kinesis_client = await exit_stack.enter_async_context(
        session.create_client('kinesis'))
    await kinesis_client.create_stream(StreamName=stream_name, ShardCount=1)

    while (describe_response := (await kinesis_client.describe_stream(
            StreamName=stream_name))) and \
            describe_response['StreamDescription']['StreamStatus'] == 'CREATING':
        print("Waiting for stream creation")
        await asyncio.sleep(1)
Beispiel #5
0
def aiobotocore_client(service, tracer):
    """Helper function that creates a new aiobotocore client so that
    it is closed at the end of the context manager.
    """
    session = aiobotocore.session.get_session()
    endpoint = LOCALSTACK_ENDPOINT_URL[service]
    client = session.create_client(
        service,
        region_name='us-west-2',
        endpoint_url=endpoint,
        aws_access_key_id='aws',
        aws_secret_access_key='aws',
        aws_session_token='aws',
    )
    Pin.override(client, tracer=tracer)
    try:
        yield client
    finally:
        client.close()