[英]Create DynamoDB table in serverless yml file
我将在 yml 文件中创建表。 当我写如下时,首先它是成功创建的。
UsersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: users
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
KeySchema:
- AttributeName: user_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
但我需要更多属性,所以我改变如下。
UsersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: users
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
- AttributeName: email_lower_case
AttributeType: S
- AttributeName: book_id
AttributeType: S
- AttributeName: book_amount
AttributeType: S
KeySchema:
- AttributeName: user_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
但它显示这样的错误。
An error occurred: UsersTable - One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions
我不想使用其他 KeySchema。 是否可以创建这样的表? 我不能使用不包含在任何索引中的属性创建表吗?
您必须在属性定义中包含键。
UsersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: users
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
- AttributeName: bitwage_user_id
AttributeType: S
- AttributeName: email_lower_case
AttributeType: S
- AttributeName: book_id
AttributeType: S
- AttributeName: book_amount
AttributeType: S
KeySchema:
- AttributeName: user_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.