使用“alexa-app”依赖项将 Alexa 技能部署到 AWS Lambda

Ber*_*rnd 2 amazon-web-services alexa aws-lambda alexa-skills-kit

我写了一个简单的 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)"
  ]
}
Run Code Online (Sandbox Code Playgroud)

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

Ron*_*sle 5

不,您需要将它与任何其他文件一起包含在 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
Run Code Online (Sandbox Code Playgroud)

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