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

时间:2017-02-24 23:50:27

标签: amazon-web-services aws-lambda alexa 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)"
  ]
}

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

1 个答案:

答案 0 :(得分:4)

不,您需要将其与任何其他文件一起包含在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目录中。