aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

DynamoDb - How to create dynamodb table with Columns(attribute name/type)?

Open sacag opened this issue 6 years ago • 10 comments

var table = new Table(this, "UniqueTable", new TableProps
            {
                TableName = "UniqueTableName",
                PartitionKey = new Attribute { Name = "EventMessageID", Type = AttributeType.STRING},
                
            });

This construct doesn't have any way to create columns (name and type). Any idea how to accomplish that, so that I do not have to write the cloudformation manually? I am referring to .NET(C#) CDK. Thanks

sacag avatar Dec 13 '19 12:12 sacag

Hi sacag,

As I know, regarding the non-relational database concepts, you need not to create columns. It will be set as long as you start to add value there according with your json object.

Ps.: Could you edit your question fixing the code markdown?

Cheers, Brenno

beuleal avatar Dec 13 '19 14:12 beuleal

You can define the attribute of a table on CloudFormation @beuleal

pushthat avatar Dec 13 '19 15:12 pushthat

@pushthat - exactly, I saw that. But, is there a code sample for this in C#? Also, if that's the case then I do not see the "AttributeDefinitions" property in the AWS CDK "Table" construct. It has to be done using the CFnTable? Why is "Table" construct missing this property? or there is some other way to define columns.

sacag avatar Dec 13 '19 18:12 sacag

@SomayaB @skinny85 - Any idea on this yet? Is this really an issue and if it is any timeline on when will it be fixed?

sacag avatar Dec 13 '19 21:12 sacag

@sacag attributes are only needed for things that are part of either keys (like the hash and sort keys), or indexes. For everything else, there are no attributes (DynamoDB is schemaless).

You define the keys when creating the Table. You add indexes with instance methods on the created table.

skinny85 avatar Dec 13 '19 22:12 skinny85

@skinny85 - Thanks for the response. Working as expected. CDK will create the table(schemaless) with indexes and keys. Attributes can be added at runtime.

sacag avatar Dec 17 '19 17:12 sacag

Glad we got this sorted out :)

skinny85 avatar Dec 17 '19 17:12 skinny85

can i add data into dynamodb table through cdk

kasarlaharish avatar Jun 27 '20 17:06 kasarlaharish

please let me help

RanjithDevelopment avatar Jul 07 '23 07:07 RanjithDevelopment

help me out to create a table

RanjithDevelopment avatar Jul 07 '23 07:07 RanjithDevelopment