What is the correct way to write asynchronous code for use with AWS Lambda?
I wrote the following code:
import asyncio
loop = asyncio.get_event_loop()
async def get_urls(event):
return {'msg':'Hello World'}
def lambda_handler(event,context):
return loop.run_until_complete(get_urls(event))
I tried the following but faster.
def lambda_handler(event, context):
# TODO implement
return {'msg':'Hello World'}
What was the correct way to write this in AWS Lambda environment?
+4
source to share
2 answers
Asynchronous execution does a lot of things at the same time. You only do one thing. You cannot do one thing faster than the time it takes to do one thing. Asynchronous execution allows you to execute independent tasks that would normally run one after the other (synchronously) at the same time, and then return the result of all tasks. Basically, you have to perform more than one operation.
+1
source to share