Amazon web services 什么';当使用aws cdk时,dynamodb的TableProps是什么

Amazon web services 什么';当使用aws cdk时,dynamodb的TableProps是什么,amazon-web-services,amazon-dynamodb,aws-cdk,Amazon Web Services,Amazon Dynamodb,Aws Cdk,我在用aws cdk做dynamodb,想添加一个dynamodb表格,已经有了这个代码,dynamodb的表格道具是什么?我以为是字符串类型的表名,但似乎错了,有人能帮我吗 这就是错误所在 lib/dynamodb.ts:8:46 - error TS2345: Argument of type '{ tableName: string; }' is not assignable to parameter of type 'TableProps'. Property 'partition

我在用aws cdk做dynamodb,想添加一个dynamodb表格,已经有了这个代码,dynamodb的表格道具是什么?我以为是字符串类型的表名,但似乎错了,有人能帮我吗

这就是错误所在

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.

试一试


TableProps扩展了TableOptions,并且“partionKey”是使用
dynamodb.table
创建表所必需的属性。我认为aws CDK文档可以更清楚地说明“TableProps”如何使用“TableOptions”

导出接口TableProps扩展TableOptions

在“partionKey”部分的TableOptions下,它显示:

只读分区键:属性

在“partionKey”和“:”之间没有“?”标记,表示此属性是必需的


我在答案中添加了导入语句。
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.

import { AttributeType } from '@aws-cdk/aws-dynamodb';

    new dynamodb.Table(this, 'MyFirstTable', {
      tableName: "myTable",
      partitionKey: {
            name: "MyPartitionkey,
            type: AttributeType.STRING
          }
    });