简体   繁体   中英

Unable to PUT to DynamoDB from a Python Lambda function

Im using a Lambda function to get and put data to DynamoDB.

I am able to put a new item into my table, but when I try to pass anything other than KEY I get the following error:

An error occurred (ValidationException) when calling the UpdateItem operation: 
The provided key element does not match the schema

This works (with key only):

"body": "{\"TableName\":\"myExampleTableName\",\"Key\":{\"id\": {\"S\": \"SomeID\"}}}"

This throws error(with key and some data):

"body": "{\"TableName\":\"myExampleTableName\",\"Key\":{\"id\": {\"S\": \"SomeID\"},\"Data\": {\"S\": \"MyDataExampleData\"}}}"

Although it seems to be the same syntax as the example shows here .

Anybody see what I am doing wrong?

Here's the my body in a more readable way:

{
    "TableName":"myExampleTableName",
    "Key":{
        "id": {"S": "SomeID"},
        "Data": {"S": "MyDataExampleData"}
    }
}

The "Data" field inside the "Key" doesn't seem right. It would be easier to understand if we had the actual code and the schema of the table you're trying to put.

This is an example using python, where you can see that there's no "Key" attribute, but "Item" (I'm assuming you're using python based on the doc you've sent)

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.03.html

response = table.put_item(
   Item={
        'year': year,
        'title': title,
        'info': {
            'plot': plot,
            'rating': rating
        }
    }
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM