【问题标题】:Deploy Alexa skill to AWS Lambda with "alexa-app" dependency使用“alexa-app”依赖项将 Alexa 技能部署到 AWS Lambda
【发布时间】:2017-07-15 23:12:52
【问题描述】:

我写了一个简单的 Alexa 技能。它使用“alexa-app”作为依赖。

var alexa = require('alexa-app');

当我保存并测试我的技能时,我得到以下响应

{
  "errorMessage": "Cannot find module 'alexa-app'",
  "errorType": "Error",
  "stackTrace": [
    "Function.Module._load (module.js:276:25)",
    "Module.require (module.js:353:17)",
    "require (internal/module.js:12:17)",
    "Object.<anonymous> (/var/task/index.js:4:13)",
    "Module._compile (module.js:409:26)",
    "Object.Module._extensions..js (module.js:416:10)",
    "Module.load (module.js:343:32)",
    "Function.Module._load (module.js:300:12)",
    "Module.require (module.js:353:17)"
  ]
}

是否可以使用此“alexa-app”依赖项而不将其烘焙到 zip 文件中。为了加快开发速度,我更喜欢在在线 Lambda 代码编辑器中只使用一个文件。这可能吗?

【问题讨论】:

  • 不,把它烤进去。

标签: amazon-web-services aws-lambda alexa alexa-skills-kit


【解决方案1】:

不,您需要将其与任何其他文件一起包含在 zip 中。不过确实不难做到。您可以使用AWS CLI 来简化此操作。

这是我在 Mac 上使用的 bash 脚本:

# Create archive if it doesn't already exist
# Generally not needed, and just a refresh is performed
if [ ! -f ./Archive.zip ];
then
  echo "Creating Lambda.zip"
else
  echo "Updating existing Lambda.zip"
fi

# Update and upload new archive
zip -u -r Lambda.zip index.js src node_modules
echo "Uploading Lambda.zip to AWS Lambda";
aws lambda update-function-code --function-name ronsSkill --zip-file fileb://Lambda.zip

在上面的脚本中,它打包了一个 index.js 文件以及 ./src 和 ./node_modules 目录中的所有文件。它正在将它们上传到我的“ronsSkill”Lambda 函数。 我也使用alexa-app,它被npm包含在node_modules目录中。

【讨论】:

  • 此响应是在亚马逊宣布 ASK CLI 之前做出的。它仍然有效,但 ask-cli 值得一试,并且可以在没有上述脚本的情况下做同样的事情。见developer.amazon.com/docs/smapi/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
相关资源
最近更新 更多