This rule raises an issue when the AWS Lambda handler function is declared with async.
The standard AWS Lambda Python runtime is designed to invoke a synchronous handler function. While Python’s asyncio library can be
used inside a synchronous handler, by calling asyncio.run(), the handler function itself cannot be declared with async def.
Doing so will lead to a runtime error.
To fix this issue, remove the async keyword from the handler function definition. The asynchronous part of the code can be moved to
its own async function.
def some_logic():
...
async def lambda_handler(event, context): # Noncompliant: the handler is defined with async
result = some_logic()
return {"status": result}
import asyncio
async def some_logic():
...
def lambda_handler(event, context):
result = asyncio.run(some_logic())
return {"status": result}