I was able to put, delete, and update and attribute with no problem of and item from my dynamoDB, but the problem that I am facing I when I want to update a Map inside of a List because it's seems that is concatenating a lot of maps and entering into a infinite loop and I got this error:
"An error occurred (ValidationException) when calling the UpdateItem operation: ExpressionAttributeValues contains invalid value: Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit for key :incidencestoDel"
I'll give you and easy example in order that you can follow what I am doing and help me.
So imagine that I want update a list in dynamodb for the same list.
import json
import boto3
import random
dynamodb = boto3.resource('dynamodb', endpoint_url="https://dynamodb.eu-west-1.amazonaws.com ")
table = dynamodb.Table('dev_pharma-orders')
def handle_modify(record):
print("Handling MODIFY Event")
#HERE IS WHERE I TAKE THE LIST FROM THE EVENT MODIFY
incidences2 = record['dynamodb']['NewImage']['incidences']['L']
#CREATE AN EMPTY LIST
newIncidences=[]
#ADDING TO A LIST
for incidence in incidences2:
newIncidences.append(incidence)
table.update_item(
Key={
#KEY OF THE TABLE
"order_id":record['dynamodb']['NewImage']['order_id']['S']
},
UpdateExpression="set incidences=:incidencestoDel",
ExpressionAttributeValues={
#HERE IS WHERE I GOT THE INFINITE LOOP AND ERROR --> CONCATENATING A LOT OF MAPS
':incidencestoDel': newIncidences
}
)
def lambda_handler(event, context):
#1. Iterate over each record
try:
for record in event['Records']:
#2. Handle event by type
if record['eventName'] == 'MODIFY':
handle_modify(record)
return "Success!"
except Exception as e:
print(e)
return "Error"
It seems that is entering all the time like infinite loop into the function "handle_modify(record):"
Here is one of the outputs:
{'M': {'M': {'M': {'createTime': {'M': {'S': {'S': '2021-01-25T12:33:09+00:00'}}}, 'lastUpdate': {'M': {'S': {'S': '2021-01-25T12:33:15+00:00'}}}, 'origin': {'M': {'S': {'S': 'MANUAL'}}}, 'details': {'M': {'M': {'M': {'comments': {'M': {'S': {'S': 'Producto sin stock'}}}}}}}, 'type': {'M': {'S': {'S': 'OUT_OF_STOCK'}}}, 'resolution': {'M': {'M': {'M': {'action': {'M': {'S': {'S': 'USER_PHARMACY_CHANGED'}}}, 'description': {'M': {'NULL': {'BOOL': True}}}, 'resolutionTime': {'M': {'M': {'M': {}}}}}}}}, 'resolved': {'M': {'BOOL': {'BOOL': True}}}, 'status': {'M': {'S': {'S': 'RESOLVED'}}}}}}}
question from:
https://stackoverflow.com/questions/65893133/an-error-occurred-validationexception-when-calling-the-updateitem-operation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…