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_error_handling.py
More file actions
34 lines (27 loc) · 960 Bytes
/
getting_started_error_handling.py
File metadata and controls
34 lines (27 loc) · 960 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
30
31
32
33
34
from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.utilities.batch import (
BatchProcessor,
EventType,
process_partial_response,
)
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
from aws_lambda_powertools.utilities.typing import LambdaContext
processor = BatchProcessor(event_type=EventType.SQS)
tracer = Tracer()
logger = Logger()
class InvalidPayload(Exception): ...
@tracer.capture_method
def record_handler(record: SQSRecord):
payload: str = record.body
logger.info(payload)
if not payload:
raise InvalidPayload("Payload does not contain minimum information to be processed.") # (1)!
@logger.inject_lambda_context
@tracer.capture_lambda_handler
def lambda_handler(event, context: LambdaContext):
return process_partial_response( # (2)!
event=event,
record_handler=record_handler,
processor=processor,
context=context,
)