AWS Lambda with DynamoDB Streams: Unexpected 'ConditionCheckFailed' scenarios
I'm trying to figure out I've been banging my head against this for hours. I'm currently implementing a Lambda function triggered by DynamoDB Streams to process item updates and log changes to another DynamoDB table. I keep working with a `ConditionalCheckFailedException` when trying to update items in the destination table. My Lambda function is supposed to take the old and new values from the stream event, check if the item already exists in the destination table, and update it if it does. Here's a snippet of my Lambda function: ```python import json import boto3 from botocore.exceptions import ClientError dynamodb = boto3.resource('dynamodb') destination_table = dynamodb.Table('MyDestinationTable') def lambda_handler(event, context): for record in event['Records']: if record['eventName'] == 'MODIFY': new_image = record['dynamodb']['NewImage'] old_image = record['dynamodb']['OldImage'] item_id = new_image['id']['S'] try: response = destination_table.update_item( Key={'id': item_id}, UpdateExpression='SET status = :new_status', ConditionExpression='status = :old_status', ExpressionAttributeValues={ ':new_status': new_image['status']['S'], ':old_status': old_image['status']['S'] } ) except ClientError as e: print(e.response['behavior']['Message']) return { 'statusCode': 200, 'body': json.dumps('Process completed') } ``` I have verified that the status in `old_image` matches the current item in the destination table before the update, so I'm puzzled as to why I'm getting the exception. The table has a global secondary index on the status field, which is used elsewhere, but I don't think that should affect this particular update. I've tried adjusting the `ConditionExpression` to remove the check on `status`, but then the Lambda function executes successfully without updating the item correctly, which defeats the purpose. Additionally, I added logging to check the values of `old_image['status']['S']` and `new_image['status']['S']`, and they appear correct in the logs. Anyone experienced similar issues with DynamoDB Streams and Lambda, or have insights into what might be going wrong? This issue appeared after updating to Python stable. What would be the recommended way to handle this?