0

I need to send messages to SQS queue from aiohttp service. I read documentation of aiobotocore and all examples, but I don`t see anything how to send messages same as postgres from aipg for example.

async def pg_engine(app):
    app['pg_engine'] = await create_engine(
        user='postgre',
        database='postgre',
        host='localhost',
        port=5432,
        password=''
    )
    yield
    app['pg_engine'].close()
    await app['pg_engine'].wait_closed()

app.cleanup_ctx.append(pg_engine)

UPD The solution is

async def sqs_client(app):
    session = get_session(loop=app.loop)
    app['sqs'] = session.create_client('sqs',
                                       endpoint_url=SQS_QUEUE_URL,
                                       region_name=SQS_REGION)
    yield
    # close connection after finish
    await app['sqs'].close()

app.cleanup_ctx.append(sqs_client)

0 Answers0