更新DynamoDB时出现客户端错误?

时间:2020-07-21 10:24:37

标签: python amazon-web-services aws-lambda amazon-dynamodb

代码在下面

import boto3
dynamodb = boto3.resource ('dynamodb')
table =dynamodb.Table('test')
def lambda_handler(event, context):
    response = table.update_item(
        Key={
            'id': "100",
            'name': "David"
            })

我已经创建了一个DynamoDB表test,我的主键是id,它是字符串。

在DynamoDB中,id 100的表值是John,我需要更新为David。上面是代码。为什么错误会引发元模式

完全错误低于

“ errorMessage”:“调用UpdateItem操作时发生错误(ValidationException):更新表达式中提供的文档路径对于更新无效”, “ errorType”:“ ClientError”,

尝试以下代码

import boto3
dynamodb = boto3.resource ('dynamodb')
table =dynamodb.Table('test')
def lambda_handler(event, context):
    response = table.update_item(
    Key={
        'id': '100'
        },
    UpdateExpression='SET name = :val1',
    ExpressionAttributeValues={
        ':val1': 'David'
    })

再添加一张表格来复制案件

放置表格:输出>>成功

在DynamoDB中首先创建表newTable

import boto3

def lambda_handler(event, context):
    dynamodb = boto3.resource ('dynamodb')
    table =dynamodb.Table('newTable')
    response = table.put_item(
    Item={
        'username': 'Ac',
        'first_name': 'DEF',
        'last_name': 'FHI',
        'age': 10,
        'account': 'GOld'
    })

如何获取物品?输出>>错误

import boto3

def lambda_handler(event, context):
    dynamodb = boto3.resource ('dynamodb')
    table =dynamodb.Table('newTable')
    response = table.get_item(
        Key={
            'username':'Ac'
        }
        )
    print (response)

错误>>响应: “ errorMessage”:“调用GetItem操作时发生错误(ValidationException):提供的键元素与架构不匹配”, “ errorType”:“ ClientError”,

1 个答案:

答案 0 :(得分:1)

第二个答案

获取和更新需要准确的项目而不是批量更新,因此您还需要提供相应的排序键

礼貌@Sairsreenivas

Other