我有一个云形式项目,具有以下配置。

问题描述 投票:0回答:0
我有以下代码,试图连接到DynamoDB并失败。

try { const client = new DynamoDBClient({ endpoint: "http://localhost:4566" }); await client.send(new UpdateItemCommand({ TableName: process.env.dbStorage, Key: marshall({id: "test"}), ExpressionAttributeValues: marshall({":test": "hello world"}), UpdateExpression: "SET test = :test", })); // const x = await client.send(new GetItemCommand({ TableName: process.env.dbStorage, Key: marshall({id: "test"}), })) console.log("JSON.stringify(x)"); console.log(JSON.stringify(x)); } catch (ex) { console.log("JSON.stringify(ex)") console.log(JSON.stringify(ex)) }

这是错误。
{ "errno": -111, "code": "ECONNREFUSED", "syscall": "connect", "address": "127.0.0.1", "port": 4566, "$metadata": { "attempts": 1, "totalRetryDelay": 0 } }

我还尝试创建客户端而没有任何参数,并且也失败了。

const client = new DynamoDBClient();

这是错误。

{ "name": "UnrecognizedClientException", "$fault": "client", "$metadata": { "httpStatusCode": 400, "requestId": "VAHE0KG1D1UTE9AQNAREF9RJHFVV4KQNSO5AEMVJF66Q9ASUAAJG", "attempts": 1, "totalRetryDelay": 0 }, "__type": "com.amazon.coral.service#UnrecognizedClientException", "message": "The security token included in the request is invalid." }
如何从配置和/或如何访问这些资源来创建DynamoDB资源?

update

我正在使用此端点,似乎可以将客户端连接到localstack。
        const client = new DynamoDBClient({
            endpoint: "http://host.docker.internal:4566",
        });

我在进行A

GetItemCommand
时会遇到以下错误

ResourceNotFoundException: Cannot do operations on a non-existent table at deserializeAws_json1_0ResourceNotFoundExceptionResponse (/var/task/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3036:23) at deserializeAws_json1_0GetItemCommandError (/var/task/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:1729:25) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async /var/task/node_modules/@aws-sdk/client-dynamodb/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24 at async /var/task/node_modules/@aws-sdk/client-dynamodb/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:11:20 at async StandardRetryStrategy.retry (/var/task/node_modules/@aws-sdk/client-dynamodb/node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46) at async /var/task/node_modules/@aws-sdk/client-dynamodb/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22 at async module.exports (/var/task/interaction/instant/help/help.js:31:19) at async Runtime.exports.handler (/var/task/handler.js:94:16) { '$fault': 'client', '$metadata': { httpStatusCode: 400, requestId: '3ad8e2c9-be76-449d-bc86-4b529f3ca45b', extendedRequestId: undefined, cfId: undefined, attempts: 1, totalRetryDelay: 0 }, __type: 'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException' }

	
您解决问题了吗?我面临同样的问题


aws-lambda amazon-dynamodb aws-cloudformation localstack
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.