generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathgetting_started_async.py
More file actions
29 lines (22 loc) · 897 Bytes
/
getting_started_async.py
File metadata and controls
29 lines (22 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import httpx # external dependency
from aws_lambda_powertools.utilities.batch import (
AsyncBatchProcessor,
EventType,
async_process_partial_response,
)
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
from aws_lambda_powertools.utilities.typing import LambdaContext
processor = AsyncBatchProcessor(event_type=EventType.SQS)
async def async_record_handler(record: SQSRecord):
# Yield control back to the event loop to schedule other tasks
# while you await from a response from httpbin.org
async with httpx.AsyncClient() as client:
ret = await client.get("https://httpbin.org/get")
return ret.status_code
def lambda_handler(event, context: LambdaContext):
return async_process_partial_response(
event=event,
record_handler=async_record_handler,
processor=processor,
context=context,
)