DIfficulty将全局二级索引添加到DynamoDB中的现有表

时间:2015-07-29 21:45:16

标签: amazon-dynamodb

表:EmailMessages

EntityId - HashKey:String

Id - RangeKey:String

名称 - 字符串

状态 - 字符串

我想为状态

创建一个GlobalSecondaryIndex
var request = new UpdateTableRequest
        {
            TableName = "EmailMessages",
            GlobalSecondaryIndexUpdates = new List<GlobalSecondaryIndexUpdate>
            {
                new GlobalSecondaryIndexUpdate
                {
                    Create = new CreateGlobalSecondaryIndexAction
                    {
                        IndexName = "GSI_EmailMessages_Status",
                        KeySchema = new List<KeySchemaElement>
                        {
                            new KeySchemaElement("Status", KeyType.HASH)
                        }
                    }
                }
            }
        };

        var client = DynamoDBManager.DBFactory.GetClient();

        client.UpdateTable(request);

然而,我得到的返回错误是500错误,没有返回文本,所以我不确定我需要纠正什么来使这项工作。我已经挖掘了文档,我似乎无法在为现有表创建GSI方面找到太多帮助。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我设法解决了我的问题。事实证明我需要更多代码。我会发布我的解决方案以防其他人遇到这个类似的问题,因为似乎没有多少资源用于Dynamo。请注意我的读写能力非常低,因为这适用于开发环境。您可能需要根据需要考虑增加您的

var request = new UpdateTableRequest
        {
            TableName = "EmailMessage",
            AttributeDefinitions = new List<AttributeDefinition>
            {
                new AttributeDefinition
                {
                    AttributeName = "Status",
                    AttributeType = ScalarAttributeType.S
                }
            },
            GlobalSecondaryIndexUpdates = new List<GlobalSecondaryIndexUpdate>
            {
                new GlobalSecondaryIndexUpdate
                {
                    Create = new CreateGlobalSecondaryIndexAction
                    {
                        IndexName = "GSI_EmailMessage_Status",
                        KeySchema = new List<KeySchemaElement>
                        {
                            new KeySchemaElement("Status", KeyType.HASH)
                        },
                        Projection = new Projection
                        {
                            ProjectionType = ProjectionType.ALL
                        },
                        ProvisionedThroughput = new ProvisionedThroughput
                        {
                            ReadCapacityUnits = 4,
                            WriteCapacityUnits = 1,
                        }
                    }
                }
            }
        };

        var client = DynamoDBManager.DBFactory.GetClient();

        client.UpdateTable(request);