gpt4 book ai didi

amazon-web-services - 如何将Dynamoose与AWS SAM结合使用?

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

假设我有以下用于创建 DynamoDB 表的 AWS SAM 资源:

EmployeeTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Employee
AttributeDefinitions:
- AttributeName: EmployeeId
AttributeType: S
- AttributeName: LocationId
AttributeType: S
- AttributeName: DepartmentId
AttributeType: S
KeySchema:
- AttributeName: EmployeeId
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: Location-index
KeySchema:
- AttributeName: LocationId
KeyType: HASH
Projection:
ProjectionType: ALL
BillingMode: PAY_PER_REQUEST

我想通过 Dynamoose 与 DynamoDB 交互。

在 Dynamoose 中,我们有 ModelSchema帮助我们定义表格形状的资源。

因为我已经在 AWS SAM 模板中创建了表和架构(属性、索引等),所以我应该如何使用 Dynamoose Schema?我应该如何使用索引?

谢谢!

最佳答案

以下是我们如何使用 dynamoose 实现 dynamodb 表。架构可以这样写:

const schema = new dynamoose.Schema({
EmployeeId: {
type: String,
required: true,
hashKey: true,
},
LocationId: {
type: String,
required: true,
index: [
{
global: true,
name: 'Location-index',
throughput: { read: 1, write: 1 },
project: true,
},
],
},
DepartmentId: {
type: String,
required: true,
},
});

对于模型,我们只需要传递架构,例如:

const Employee = dynamoose.model("Employee", schema);

关于amazon-web-services - 如何将Dynamoose与AWS SAM结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75200581/

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