Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to write asyncio 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 was trying to accomplish the following but faster.


def lambda_handler(event, context):
    # TODO implement
    return {'msg':'Hello World'}

What was the correct way to write this in an AWS Lambda environment?

like image 238
man2xxl Avatar asked Apr 25 '17 02:04

man2xxl


1 Answers

Works for me... You need to choose Runtime "Python 3.6" or "Python 3.7".

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))

enter image description here

like image 186
Messa Avatar answered Sep 18 '22 09:09

Messa