如何使用dynamoose查询本地dynamoDB?

问题描述 投票:0回答:5

作为一名开发人员,我不想一直连接到 Amazon Web 服务,因此我在本地计算机上安装了 DynamoDB,参考了 AWS 文档。我在后端使用node.js。

我在生产中使用 dynamoose 作为 Amazon DynamoDB 的建模工具,如何使用相同的 dynamoose 来查询本地 DynamoDB 表以进行开发?

javascript node.js amazon-dynamodb dynamoose
5个回答
2
投票

您只需在代码中使用它即可:

dynamoose.local();

假设您的应用程序中有一个属性文件,您可能需要一个属性标志来指示您是处于开发状态还是处于生产状态。然后在您的代码中获取属性,如果您处于开发阶段,请运行 dynamoose.local() 行。

编辑:我不使用 javascript 编写代码,但它会是这样的:

const { NODE_ENV } = process.env
if (NODE_ENV == "DEV") {
    dynamoose.local();
}

假设您的应用程序中有一个属性文件,您在其中设置了一个名为“environment”的系统属性,其值为“DEV”或“PROD”。


2
投票

可能有版本问题,但我必须这样做

var dynamoose = require('dynamoose');
dynamoose.aws.ddb.local();

1
投票

下面的代码应该允许您设置 Dynamoose 以在本地使用。

var dynamoose = require('dynamoose');
dynamoose.local('http://localhost:8000');

这假设 DynamoDB 在端口 8000 上本地运行。如果您没有在端口 8000 上运行 DynamoDB Local,则必须更新上面的第二行以反映正确的端口。

编辑

正如评论中提到的,您不需要指定

'http://localhost:8000'
,因为这些是默认值。如果您不使用端口 8000 和主机 localhost 的默认选项,您当然可以将端口或主机更改为您想要的。


1
投票

如果您正在寻找更新版本的 dynamoose,正确的语法是。

dynamoose.aws.ddb.local(http://localhost:8000)

https://dynamoosejs.com/guide/Dynamoose/#dynamooseawsddblocalendpoint


0
投票

我有这个问题 Nest] 31938 - 04/12/2024, 10:53:46 AM 错误 [UnrecognizedClientException: 访问密钥 ID 或安全令牌无效。] 连接 DynamoDB 时出错

/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@smithy/smithy-client/dist-cjs/index.js:838 const 响应 = 新的异常Ctor({ ^ UnrecognizedClientException:访问密钥 ID 或安全令牌无效。 在 throwDefaultError (/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@smithy/smithy-client/dist-cjs/index.js:838:20) 在/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@smithy/smithy-client/dist-cjs/index.js:847:5 在 de_CommandError (/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2231:14) 在 processTicksAndRejections (节点:内部/进程/task_queues:95:5) 在/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20 在/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@smithy/core/dist-cjs/index.js:165:18 在/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38 在/home/abelacco/pideGo/backend/ms-rep-his-api/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22 在 DynamodbService.onModuleInit (/home/abelacco/pideGo/backend/ms-rep-his-api/src/shared/dynamodb/services/dynamodb.service.ts:44:22) 在异步 Promise.all(索引 0) 等待调试器断开连接...

© www.soinside.com 2019 - 2024. All rights reserved.