gpt4 book ai didi

node.js - 在 serverless.yml 中创建两个 dynamoDB 表

转载 作者:行者123 更新时间:2023-12-03 12:16:26 25 4
gpt4 key购买 nike

我尝试将 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

读写容量单位:-

You specify throughput capacity in terms of read capacity units and write capacity units:

One read capacity unit represents one strongly consistent read per second, or two eventually consistent reads per second, for an item up to 4 KB in size. If you need to read an item that is larger than 4 KB, DynamoDB will need to consume additional read capacity units. The total number of read capacity units required depends on the item size, and whether you want an eventually consistent or strongly consistent read. One write capacity unit represents one write per second for an item up to 1 KB in size. If you need to write an item that is larger than 1 KB, DynamoDB will need to consume additional write capacity units. The total number of write capacity units required depends on the item size.

Read and write capacity units

关于node.js - 在 serverless.yml 中创建两个 dynamoDB 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com