调用UpdateItem操作时发生错误(ValidationException)

2024-09-26 23:17:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我能够从dynamoDB中放置、删除和更新and属性,而没有and项的问题,但是当我想要更新列表中的映射时,我面临的问题是,因为它似乎连接了很多映射并进入无限循环,我得到了以下错误: “调用UpdateItem操作时发生错误(ValidationException):ExpressionAttributeValues包含无效值:嵌套级别已超过支持的限制:项中的属性的嵌套级别超出了键:IncidenceTodel的支持限制”

我会给你们举一个简单的例子,以便你们能理解我在做什么并帮助我。 想象一下,我想在dynamodb中为同一个列表更新一个列表


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"

似乎一直像无限循环一样进入函数“handle\u modify(record):”

以下是其中一个输出:

{'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'}}}}}}}


Tags: andoftheimportevent列表属性record

热门问题