表:EmailMessages
EntityId - HashKey: String
Id - RangeKey: String
Name - 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的太多帮助。如有任何帮助,不胜感激
我设法解决了我的问题。结果发现我需要更多的代码。我要张贴我的解决方案,以防有人遇到类似的问题,因为似乎没有很多资源在那里的发电机。请注意,我的读写能力非常低,因为这是针对开发环境的。你可以考虑根据你的需要增加你的
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);