Reputation: 89
I'm using aws cdk for dynamodb, wanna add a dynamodb table, already got this code, what's the TableProps for dynamodb? I thought it's table name with string type, but seems wrong, can anyone help me with that?
import core = require('@aws-cdk/core');
import dynamodb = require('@aws-cdk/aws-dynamodb')
export class HelloCdkStack extends core.Stack {
constructor(scope: core.App, id: string, props?: core.StackProps) {
super(scope, id, props);
new dynamodb.Table(this, 'MyFirstTable', {
tableName: 'myTable'
});
}
}
This is the error
lib/dynamodb.ts:8:46 - error TS2345: Argument of type '{ tableName: string; }' is not assignable to parameter of type 'TableProps'.
Property 'partitionKey' is missing in type '{ tableName: string; }' but required in type 'TableProps'.
8 new dynamodb.Table(this, 'MyFirstTable', {
~
9 tableName: 'myTable'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 });
~~~~~~~
node_modules/@aws-cdk/aws-dynamodb/lib/table.d.ts:19:14
19 readonly partitionKey: Attribute;
~~~~~~~~~~~~
'partitionKey' is declared here.
Upvotes: 0
Views: 2399
Reputation: 9
TableProps extends TableOptions and "partionKey" is a required property for creating a table with dynamodb.Table
. I think the aws CDK documentation could be more clear about how "TableOptions" is used by "TableProps".
export interface TableProps extends TableOptions
Under TableOptions in the "partionKey" section it says:
readonly partitionKey: Attribute;
Without a "?" mark between "partionKey" and the ":" it means this property is required.
Upvotes: 0
Reputation: 12203
Try
import { AttributeType } from '@aws-cdk/aws-dynamodb';
new dynamodb.Table(this, 'MyFirstTable', {
tableName: "myTable",
partitionKey: {
name: "MyPartitionkey,
type: AttributeType.STRING
}
});
Upvotes: 2