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

Python 更新DynamoDB时出现客户端错误?,python,amazon-web-services,aws-lambda,amazon-dynamodb,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"

代码如下

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中,
id100
的表值是
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):提供的键元素与架构不匹配”, “错误类型”:“ClientError”,第二个错误的答案

get和update需要更新的是确切的项目,而不是批次,因此您还需要提供相应的排序键

礼节@Sairsreenivas

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': 'GH',
    #     'age': 10,
    #     'account': 'GOld'
    # })
    # try:
    #     response = table.get_item(Key={'username':'Mak'})
    # except Exception as e:
    #     print(e.response['Error']['Message'])
    # else:
    #     return response['Item']
    # item = response['Item']
    # print (item)
    #Get Item
    response = table.get_item(Key={'username':'Ac', 'last_name':'GH'})
    print (response['Item'])
    table.update_item(
        Key ={
            'username':'Ac', 'last_name':'GH'
        },
        UpdateExpression = 'SET age = :value1',
        ExpressionAttributeValues={
            ':value1':20
        }
        )
    print ("After update \n")
    response = table.get_item(Key={'username':'Ac', 'last_name':'GH'})
    print (response['Item'])

您可以发布错误消息吗?@Marcin“调用UpdateItem操作时发生错误(ValidationException):提供的键元素与架构不匹配”,ClientError@Marcin没有快捷键模式是什么?@Marcin两者都是
字符串