【问题标题】:Nodejs DynamoDB CreateTable hash only with no range returns ValidationExceptionNodejs DynamoDB CreateTable 哈希仅没有范围返回 ValidationException
【发布时间】:2014-10-31 03:53:35
【问题描述】:

我正在尝试通过他们的aws-sdk on nodejsdynamodb 上创建一个表。 下面是我在 dynamodb.createTable 上传递的参数:

{
    TableName: 'new_table',
    ProvisionedThroughput: {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1
    },
    KeySchema: [
        {AttributeName: 'primary_key', KeyType: 'HASH'}
    ],
    AttributeDefinitions: [
        {AttributeName: 'primary_key', AttributeType: 'S'},
        {AttributeName: 'some_attribute', AttributeType: 'S'}
    ]
}

这会返回

ValidationException: One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions

我已通过在“KeySchema”上添加“some_attribute”来解决此问题,但我想要的是一个没有“范围”的仅“哈希”表。

【问题讨论】:

    标签: node.js amazon-web-services amazon-dynamodb create-table


    【解决方案1】:

    已解决:创建表时,您只需要指定 KeySchema 属性,而不是您将放在表上的所有属性。所以在我的情况下,我只需要指定'primary_key'

    {
        TableName: 'new_table',
        ProvisionedThroughput: {
            ReadCapacityUnits: 1,
            WriteCapacityUnits: 1
        },
        KeySchema: [
            {AttributeName: 'primary_key', KeyType: 'HASH'}
        ],
        AttributeDefinitions: [
            {AttributeName: 'primary_key', AttributeType: 'S'},
        ]
    }
    

    【讨论】:

    • 谢谢。我也偶然发现了同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    相关资源
    最近更新 更多