当前位置: 首页 > 知识库问答 >
问题:

在本地运行Amazon Alexa Skill,而不是AWS Lambda(Javascript)

燕野
2023-03-14

有没有可能用ngrok代替AWS在本地运行alexa skill?我在AWS Lambda中建立了一项技能,但我更愿意使用自己的服务器。如何在本地运行Alexa?

我尝试 https://github.com/alexa-js/alexa-app-server 但这有任何意义,因为我需要重写整个代码:(更好的解决方案是 http://docs.bespoken.tools/en/latest/tutorials/tutorial_lambda_nodejs/ 但不是最好的。它只是只适用于一个惠康的意图,并在:(

bespken命令的终端日志:

    BST: v0.9.35  Node: v7.8.0

Your URL for Alexa Skill configuration:
https://proxy.bespoken.tools?node-id=33efccba-2246-477f-bbb8-2e1e510cce9d

INFO  2017-04-25T20:27:20.628Z Connected - proxy.bespoken.tools:5000
INFO  2017-04-25T20:27:26.812Z RequestReceived: POST /?node-id=33efccba-2246-477f-bbb8-2e1e510cce9d ID: 1493152039146
INFO  2017-04-25T20:27:26.815Z Forwarding localhost:10000
Current hour: 24
Warning: Application ID is not set
INFO  2017-04-25T20:27:27.939Z ResponseReceived ID: 1493152039146
INFO  2017-04-25T20:28:10.755Z RequestReceived: POST /?node-id=33efccba-2246-477f-bbb8-2e1e510cce9d ID: 1493152078963
INFO  2017-04-25T20:28:10.756Z Forwarding localhost:10000
Warning: Application ID is not set
INFO  2017-04-25T20:28:11.157Z ResponseReceived ID: 1493152078963
INFO  2017-04-25T20:28:51.073Z RequestReceived: POST /?node-id=33efccba-2246-477f-bbb8-2e1e510cce9d ID: 1493152113739
INFO  2017-04-25T20:28:51.073Z Forwarding localhost:10000
Warning: Application ID is not set
INFO  2017-04-25T20:28:51.995Z ResponseReceived ID: 1493152113739

共有3个答案

汪典
2023-03-14

你可以按照下面的教程在本地测试你的alexa技能:

如何在本地测试 Alexa

阳狐若
2023-03-14

这里有一些示例代码,您可以使用它们轻松地在本地运行Lambda,将该文件命名为AlexaLambda.js:

const log = require('console');
var AWS = require('aws-sdk');

AWS.config.region = "us-east-1";
AWS.config.update({
    accessKeyId: "----",
    secretAccessKey: "----",
});

/**
 * Wraps the actual underlying Alexa lambda initialization in a 
 * Promise. Injects test mocks where appropriate.
 */
var initializerPromise = new Promise(function(fulfill, reject) {
    // Mock out certain imports here if you want but not necessary
    /*
  var Module = require('module');
  var originalRequire = Module.prototype.require;
  Module.prototype.require = function() {
    if ((arguments[0] == 'S3FeedService') ||
        (arguments[0] == './lib/S3FeedService')) {
      return MockS3Service;
    } else if ((arguments[0] == 'WebsocketService') ||
               (arguments[0] == './lib/WebsocketService')) {
      return WSMockService;
    } else if ((arguments[0] == 'SQSService') ||
               (arguments[0] == './lib/SQSService')) {
      return SQSMockService;
    } else {
      return originalRequire.apply(this, arguments);
    }
  };*/
  // Import your actual lambda here.
  var lambda = require('../src/index.js');
  fulfill(lambda);

});

/**
 * The Alexa Lambda context object which is called upon completion
 * of lambda execution.  Also wraps the callback which contains the 
 * test assertion code of the caller.
 * @param callback - must be of the form function(error, result) {};
 * @returns
 */
function Context(callback) {
    this.clientContext = {"env": {}}; 
    this.callback = callback;
}

Context.prototype.done = function(error, result) {
    if (typeof error != "undefined" && error) {
        this.callback(error, null);
    } else {
        this.callback(null, result);
    }
}

Context.prototype.succeed = function(result) {
    this.callback(null, result);
}

Context.prototype.fail = function(error) {
    this.callback(error, null);
}

/**
 * The AlexaLambda object that's exposed for test cases.
 * @returns
 */
function AlexaLambda() {
}

/**
 * Executes the lambda function, provided an inputEvent and a 
 * callback.
 * @param inputEvent - the input event that includes the intent.
 * @param callback - called upon completion of lambda execution.
 */
AlexaLambda.prototype.execute = function(inputEvent, callback) {
    initializerPromise.then(function(lambda) {
        var context = new Context(callback);
        lambda.handler(inputEvent, context);
    });
}

/**
 * Export the lambda class, importers instantiate via new AlexaLambda();
 */
module.exports = AlexaLambda;

然后你可以像这样在你的测试中使用这个‘AlexaLambda’(在我的例子中,我使用的是Mocha):

var AlexaLambda = require('./AlexaLambda');
var Event = require('./Event');  // My 'fake' Event class

describe("Guest User Test", function() {
  var alexaLambda = new AlexaLambda();      

  it("Alexa, open/launch 60db", function(done) {
    var event = Event.createLaunchEvent();
    alexaLambda.execute(event, function(error, result) {
      validateYourResultHere();
      done();
    })
  });

接下来的问题就是通过你正在使用的任何框架来运行你的测试。

皇甫浩壤
2023-03-14

是的,有几种解决方案可以在本地运行节点lambda。例如,我一直在使用节点lambda。与大多数解决方案一样,它面向希望在本地测试然后轻松部署到AWS Lambda的用户。

如果你想自己运行它们,我会注意到微软和IBM已经将lambda的实现开源(这里是微软和IBM的)。我自己还没有真正尝试过,我要指出的是,AWS、GCP和Azure都为节点提供Lambda服务,这些服务的市场是健康的,锁定也很小,所以我觉得自己运行它的必要性不如为Dynamo这样的东西。

但我也建议你继续追求BST。我正在使用我自己的一些作品来测试我的技能,因为我在听说他们的东西之前就开始了,但是我尝试过他们的东西(BSTAlexa)非常有用,我看到他们提供了一些你需要的其他部分,以便轻松有效地测试你的技能。

 类似资料:
  • 我创建了一个测试项目(maven)来测试REST API的性能。我正在使用Jeter插件 这是我的pom片段 我有一个Jenkins文件在我的项目像这样 当我触发Jenkins上的构建时,构建成功了,我在控制台输出中看到了这一点 问题是,它什么也做不了。Performace趋势图没有显示任何东西。 如果我在本地机器上运行相同的项目,它工作得非常好。我在日志中看到类似的东西,证实了这一点。生成的输出

  • 当部署在azure中时,Swagger UI不是在。NET核心应用程序中创建的,但它在本地运行得很好

  • 问题内容: 读取子文件夹的代码如下 当我在localhost上使用时,此代码可以完美运行。但是在本地运行(即从文件位置)时不会运行。我有12个子文件夹。因此,当我使用本地主机时,输出为12,但是在本地运行时,输出仅为0。 有什么问题吗?请帮助我..我是jQuery的新手。因此,如果是我的错误,请通知它。在代码中,我仅使用html,jQuery,js,而不使用php。 问题答案: 这是因为浏览器的跨

  • 我在用MacBook。当我通过测试运行测试时,我们的Jenkins服务器正在linux服务器上运行。xml文件所有测试类都在运行,但当我运行Jenkins build时,它的not Get run错误是驱动程序不可执行 我在Jenkins中创建了maven项目,并从bitbucket中给出了该项目的回购url 有人帮我解决这个问题吗?

  • 案例1: 使用时: 获取异常: 看到的超文本标记语言套件异常:java.lang.RuntimeException:java.lang.RuntimeException: GoogleChrome在路径中找不到!请将包含“chrome.exe”或“google-chrome”或“GoogleChrome”的目录添加到您的PATH环境可用,或显式指定GoogleChrome路径,如下所示:*goog

  • 有一个简单的日志文件 /tmp/test.log 有一个简单的bash脚本 /tmp/test.sh 如果我在本地运行这个脚本,它会像预期的那样工作: 但如果我通过ssh运行此脚本,我会得到一些意想不到的结果: 有人知道为什么吗?