简体   繁体   English

在使用 AWS SAM CLI 进行本地测试时,是否可以远程使用 dynamodb?

[英]Is it possible to use dynamodb remotely - not local - while testing locally with AWS SAM CLI?

In many cases, the question is how to use aws sam cli with a "local" dynamodb ,在许多情况下,问题是如何将 aws sam cli 与“本地” dynamodb 一起使用

my question is about: how to use dynamodb that is in production, so not local.我的问题是:如何使用生产中的 dynamodb,而不是本地的。

my local nodejs script, for instance, looks like this:例如,我的本地 nodejs 脚本如下所示:

const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
dynamo.query(queryParams, function(err, data) {
             if (err) console.log(err, err.stack); // an error occurred
             else     console.log('data: '+ data);           // successful response
         });

I start my script with sam local invoke --no-event - when i query a table, how can i use a specific AWS remote resource?我使用sam local invoke --no-event启动脚本 - 当我查询表时,如何使用特定的 AWS 远程资源?

If you would like to use the specific remote resource when invoking your lambdas, like DynamoDB in your case, you can run your invoke command with the profile desired, ex: production as follow.如果您想在调用 lambda 时使用特定的远程资源,例如您的情况下的 DynamoDB,您可以使用所需的配置文件运行您的调用命令,例如:生产,如下所示。

sam local invoke --no-event --profile production

You will need to have the production profile configured in your aws credentials file.您将需要在您的 aws 凭证文件中配置生产配置文件。 if you haven't done that already you can do that as follow:如果你还没有这样做,你可以这样做:

aws configure --profile production

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM