簡體   English   中英

嘗試放置新項目時出現 DynamoDB InvalidParameterType 錯誤

[英]DynamoDB InvalidParameterType Error While Trying To Put A New Item

我正在嘗試實現一個基於 DynamoDB 的應用程序來存儲一些請求數據。 我閱讀了 DynamoDB 官方文檔,目前我正在按照這個官方教程進行一些基本操作。

我正在使用本地 DynamoDB docker 容器。 你可以用這個運行它:

docker run -d -p 8000:8000 amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb

當我嘗試按照上面給出的教程創建一個新表時,我沒有收到任何錯誤,一切都很好:

var params = {
TableName: 'book',
KeySchema: [
    {
        AttributeName: 'title',
        KeyType: 'HASH',
    }
],
AttributeDefinitions: [
    {
        AttributeName: 'title',
        AttributeType: 'S'
    }
],
ProvisionedThroughput: {
    ReadCapacityUnits: 1, 
    WriteCapacityUnits: 1, 
}

};
dynamodb.createTable(params, function(err, data) {
    if (err) print(err); // an error occurred
    else print(data); // successful response

});

但是當我嘗試在其中放入一些新項目時:

var params = {
TableName: 'book',
Item: { // a map of attribute name to AttributeValue
    title: "Sample Application: CloudList",
    chapter: 10
    }
};

dynamodb.putItem(params, function(err, data) {
    if (err) print(err); // an error occurred
    else print(data); // successful response
});

我收到了這個錯誤:

在此處輸入圖像描述

31 驗證錯誤實際上等於標題中的字符數: Sample Application: CloudList DynamoDB shell 也無法識別上述教程中給出的打印 function。 所以我不得不用 ppJson function 替換它。 我在哪里做錯了,如何通過 Web Shell 從 DynamoDB 放置/刪除/獲取項目? (也可以通過 PHP 代碼)


編輯:我也嘗試了 Vikdor 在評論中所說的,似乎我擺脫了那個UnexpectedParameter錯誤,但這次我得到了Invalid attribute value type錯誤。

var params = {
    TableName: 'book',
    Item: { // a map of attribute name to AttributeValue
        'title': {S: "Sample Application: CloudList"},
        'chapter': {N: '10'}
    }
};

文檔解釋了傳遞給 API 的paramsItem鍵的結構,您的params應如下所示:

var params = {
    TableName: "book",
    Item: { 
        "title": {"S": "Sample Application: CloudList"},
        "chapter": {"N": :10"}
    }
};

請注意,即使是數字也應該用引號引起來。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM