Idempotency config warning - couldn't determine time left #1762
-
I'm trying to process some SQS records using batch processing and idempotency. I assumed I needed to decorate my business logic function so each record is processed only once. Following the sample here. I set my code up as follows. from aws_lambda_powertools.utilities.idempotency import (
DynamoDBPersistenceLayer, IdempotencyConfig, idempotent_function)
from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType, batch_processor
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)
dynamodb = DynamoDBPersistenceLayer(table_name="workflow-events")
config = IdempotencyConfig(
event_key_jmespath="messageId",
use_local_cache=True,
)
logger = Logger(level="INFO",service="workflow_events_track")
@idempotent_function(data_keyword_argument="record", config=config, persistence_store=dynamodb)
def process_workflow_event(record: SQSRecord):
... some logic
@logger.inject_lambda_context
@batch_processor(record_handler=process_workflow_event, processor=processor)
def lambda_handler(event: dict, context: LambdaContext):
config.register_lambda_context(context) # needed for idempotent functions
return processor.response() When the lambda runs though, it raises the following warning....
I'm not sure why that's getting raised if i'm registering the context to the config in the handler. I'm also not sure what the potential impact of this could be. Could records be processed twice? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Hey! That's our fault - could you create a docs issue so we can address it, please? Solution In the meantime, here's how to address it until we correct the docs and think of a better way to handle this more seamlessly within Batch:
Explanation The decorator @batch_processor will call your record_handler function before it calls the decorated Lambda Handler (final return). Therefore, the Lambda context is only registered in the Idempotency config after all records have been processed. This doesn't impact your ability to process once, it is working. What it impacts is your ability to recover from half-completed transactions that failed during a timeout incident. |
Beta Was this translation helpful? Give feedback.
-
well, i still seem to be seeing the same error message. hoping i implemented the fix correctly |
Beta Was this translation helpful? Give feedback.
-
Allow us to reproduce and we’ll come back with a patch as soon as we can.
In-flight Wi-Fi may not be stable so bear with us
…On Wed, 7 Dec 2022 at 19:29, Andrew Harmon ***@***.***> wrote:
well, i still seem to be seeing the same error message. hoping i
implemented the fix correctly
—
Reply to this email directly, view it on GitHub
<#1762 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBE4FTZ3IITQ3VPUN4DWMDJP3ANCNFSM6AAAAAASXAMHQQ>
.
You are receiving this because you commented.Message ID:
<awslabs/aws-lambda-powertools-python/repo-discussions/1762/comments/4336021
@github.com>
|
Beta Was this translation helpful? Give feedback.
Hey!
That's our fault - could you create a docs issue so we can address it, please?
Solution
In the meantime, here's how to address it until we correct the docs and think of a better way to handle this more seamlessly within Batch:
Explanation
The decorator @batch_processor will call your record_handler function before it calls the decorated Lambda Handler (final return). Therefore, the Lambda context is only registered in the Idempotency config after all records have been processed.
This doesn't impact your ability to process once, it is worki…