小编ajh*_*stn的帖子

从 s3 读取数据:s3.getObject 不是函数

我正在尝试从 S3 读取 txt 文件来构建 Alexa 的响应。在 Lambda 中测试代码时,我收到此错误。谁能看到我哪里出错了?

错误

Error handled: s3.getObject is not a function
Run Code Online (Sandbox Code Playgroud)

我已经安装了“aws-sdk”,并且需要该模块位于我的技能的 index.js 顶部

const s3 = require('aws-sdk/clients/s3')
Run Code Online (Sandbox Code Playgroud)

处理程序代码。为了强调这一点,我使用 Async/Await 并在下面的 goGetS3 函数中返回一个 Promise。

const ChooseStoryIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
      handlerInput.requestEnvelope.request.intent.name === 'ChooseStoryIntent';
  },
  async handle(handlerInput) {
    let speechText;
    let options = {
      "Bucket": "stores",
      "Key": "person.txt"
    }
    await goGetS3(options)
      .then((response) => {
        console.log(response),
        console.log(response.Body.toString()),
          speechText = response
      })
      .catch((err) => {
        console.log(err)
        speechText = 'something wrong getting the …
Run Code Online (Sandbox Code Playgroud)

alexa-skills-kit

3
推荐指数
1
解决办法
9847
查看次数

标签 统计

alexa-skills-kit ×1