Is it possible to access the LambdaContext when using batch processing? #1238
-
If so, how? I followed the docs and my code now basically looks like this: processor = BatchProcessor(event_type=EventType.SQS)
def record_handler(record: SQSRecord):
"""
Handler for a single SQS record.
"""
# Do some cool things with record.
pass
@logger.inject_lambda_context
@event_source(data_class=SQSEvent)
@batch_processor(record_handler=record_handler, processor=processor)
def lambda_handler(event: Dict[str, SQSEvent], context: LambdaContext) -> Dict[str, Any]:
return processor.response() Is there any way to access the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
A work around would look something like this: processor = BatchProcessor(event_type=EventType.SQS)
def lambda_handler(event, context: LambdaContext):
def record_handler(record: SQSRecord):
print(context.function_name)
...
with processor(records=event["Records"], handler=record_handler):
processor.process()
return processor.response() FYI, your code example typing for |
Beta Was this translation helpful? Give feedback.
-
Hey @mew1033, What information are you looking to use within Lambda Context? Lambda runtime makes key Lambda Context data available as environment variables. If these are insufficient, please open up a feature request as it might be an useful exercise to think of ways to expose Lambda Context more generally across any utility. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Closing as this was released back then: https://docs.powertools.aws.dev/lambda/python/latest/utilities/batch/#accessing-lambda-context |
Beta Was this translation helpful? Give feedback.
Closing as this was released back then: https://docs.powertools.aws.dev/lambda/python/latest/utilities/batch/#accessing-lambda-context