我正在使用aws cdk for dynamodb,想要添加一个dynamodb表,我已经得到了这段代码,什么是dynamodb的TableProps?我还以为是字符串类型的表名呢,但是好像错了,有没有人能帮我一下?
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'
});
}
}这就是错误
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.发布于 2020-03-20 06:05:19
试一试
import { AttributeType } from '@aws-cdk/aws-dynamodb';
new dynamodb.Table(this, 'MyFirstTable', {
tableName: "myTable",
partitionKey: {
name: "MyPartitionkey,
type: AttributeType.STRING
}
});发布于 2021-06-11 02:58:29
TableProps扩展了TableOptions,"partionKey“是使用dynamodb.Table创建表所必需的属性。我认为aws CDK文档可以更清楚地说明"TableProps“如何使用"TableOptions”。
export interface TableProps extends TableOptions
在"partionKey“部分的TableOptions下,它说:
readonly partitionKey: Attribute;
不带"?“在"partionKey“和":”之间标记,表示此属性是必需的。
https://stackoverflow.com/questions/60765405
复制相似问题