1

Table: EmailMessages

EntityId - HashKey : String

Id - RangeKey : String

Name - String

Status - String

I would like to make a GlobalSecondaryIndex for Status

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);

However the return error I get is a 500 error with no return text so I'm unsure on what I need to correct to make this work. I've dug through the documentation and I can't seem to find much help on creating a GSI for an existing table. Any help would be much appreciated

2
  • Is it a requirement that you accomplish this using the API or could you just use the AWS web console to accomplish the same thing manually through the GUI? Commented Jul 29, 2015 at 21:50
  • It would be preferable Commented Jul 29, 2015 at 21:54

1 Answer 1

3

I managed to solve my issue. Turns out I needed a lot more code. I'm going to post my solution in case someone else runs into this similar issue since there doesn't seem to be many resources out there for Dynamo. Please note my read and write capacities are very low because this is for a dev environment. You might want to consider upping yours depending on your needs

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.