[英]Creating two dynamoDB tables in serverless.yml
我尝试将2个表添加到serverless.yml以与DynamoDB链接。
我在serverless.yml中的代码的一部分:
...
resources:
Resources:
ItemsTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: "InvoiceConfig"
AttributeDefinitions:
- AttributeName: "providerName"
AttributeType: "S"
KeySchema:
- AttributeName: "providerName"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
TableName: "DifferentTermsPages"
AttributeDefinitions:
- AttributeName: "id"
AttributeType: "S"
- AttributeName: "providerName"
AttributeType: "S"
- AttributeName: "productType"
AttributeType: "S"
- AttributeName: "language"
AttributeType: "S"
- AttributeName: "terms"
AttributeType: "L"
KeySchema:
- AttributeName: "id"
KeyType: "HASH"
- AttributeName: "providerName"
KeyType: "HASH"
- AttributeName: "productType"
KeyType: "HASH"
- AttributeName: "language"
KeyType: "HASH"
- AttributeName: "terms"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 10
WriteCapacityUnits: 10
那是对的吗??
我的表是:
InvoiceConfig: with columns: providerName (String)
DifferentTermsPages: id (String), providerName (String), productType (String), language (String), terms (list)
我需要在serverles.yml中进行更多更改吗? 表达式“ReadCapacityUnits”和“WriteCapacityUnits”的含义是什么?
两个资源之间应该有一些分离(即两个DynamoDB表)。
注意:-
您可以在创建DynamoDB表时仅定义关键属性。 换句话说,您不需要定义所有其他非键属性。
尝试这个:-
Resources:
ItemsTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: "InvoiceConfig"
AttributeDefinitions:
- AttributeName: "providerName"
AttributeType: "S"
KeySchema:
- AttributeName: "providerName"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
DifferentTermsPages:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: "DifferentTermsPages"
AttributeDefinitions:
- AttributeName: "id"
AttributeType: "S"
KeySchema:
- AttributeName: "id"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 10
WriteCapacityUnits: 10
读写容量单位: -
您可以根据读取容量单位和写入容量单位指定吞吐量容量:
对于最大为4 KB的项目,一个读取容量单位表示每秒一次强烈一致的读取,或每秒两次最终一致读取。 如果需要读取大于4 KB的项目,DynamoDB将需要消耗额外的读取容量单位。 所需的读取容量单位总数取决于项目大小,以及是否需要最终一致或高度一致的读取。 一个写入容量单位表示每秒最多1 KB的项目的一次写入。 如果需要编写大于1 KB的项目,DynamoDB将需要消耗额外的写入容量单位。 所需的写入容量单位总数取决于项目大小。
读取和写入容量单位是允许数据库每秒处理的最大数据大小,如果您在任何秒钟内超过此数量,则请求将限制。
可能更容易使用DynamoDB On-Demand并支付Db表的使用,而不是计算WCU和RCU。
以下是以格式化方式添加的3个表的示例,没有半引号:
resources:
Resources:
myDynamoDBTable1:
Type: AWS::DynamoDB::Table
Properties:
TableName: Table1
AttributeDefinitions:
- AttributeName: ColumnName1
AttributeType: S
- AttributeName: ColumnName2
AttributeType: N
KeySchema:
- AttributeName: ColumnName1
KeyType: HASH
- AttributeName: ColumnName2
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
myDynamoDBTable2:
Type: AWS::DynamoDB::Table
Properties:
TableName: Table2
AttributeDefinitions:
- AttributeName: ColumnName1
AttributeType: S
KeySchema:
- AttributeName: ColumnName1
KeyType: HASH
BillingMode: PAY_PER_REQUEST
myDynamoDBTableN:
Type: AWS::DynamoDB::Table
Properties:
TableName: TableN
AttributeDefinitions:
- AttributeName: ColumnName1
AttributeType: S
KeySchema:
- AttributeName: ColumnName1
KeyType: HASH
BillingMode: PAY_PER_REQUEST
返回读/写容量模式 :
示例1:假设您预见到每秒向数据库写入10KB数据的流量。 使用WCU公式,您需要(10KB / 1KB)= 10WCU。
例2:期望将7.5KB数据的流量写入db,我们需要:(7.5KB / 1KB)= 8WCU
强相合模式:向上舍入(DataSize / 4KB)
最终一致模式:向上舍入(DataSize / 4KB)/ 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.