Aws lambda 无服务器Lambda函数不';t映射到正确的响应

Aws lambda 无服务器Lambda函数不';t映射到正确的响应,aws-lambda,httpresponse,serverless,Aws Lambda,Httpresponse,Serverless,我无法正确返回使用无服务器框架部署的Lambda函数的响应: module.exports.hello = async (event, context, callback) => { const content = fs.readFileSync('./cn23_template.html', 'utf-8') const Vue = require('vue') const app = new Vue({ template: content, data:

我无法正确返回使用无服务器框架部署的Lambda函数的响应:

module.exports.hello = async (event, context, callback) => {

  const content = fs.readFileSync('./cn23_template.html', 'utf-8')

  const Vue = require('vue')
  const app = new Vue({
    template: content,
    data: function () {
      return event
    }
  })

  const renderer = require('vue-server-renderer').createRenderer()
  const html = await renderer.renderToString(app)

  const browser = await chromium.puppeteer.launch({
    // Required
    executablePath: await chromium.executablePath,

    // Optional
    args: chromium.args,
    defaultViewport: chromium.defaultViewport,
    headless: chromium.headless || true
  });

  const page = await browser.newPage();
  await page.setContent(html);
  let pdf = await page.pdf({ pageRanges: '1', format: 'a4', printBackground: true });

  await browser.close();

  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/pdf',
      'Content-Length': pdf.length
    },
    body: pdf ? pdf.toString('base64') : null,
    isBase64Encoded: true
  }
}
我的
serverless.yml
文件:

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: post
          integration: lambda
          response:
            headers:
              Content-Type: "'Test'"
              Cache-Control: "'max-age=120'"
问题是我从函数返回的内容没有正确映射到响应。响应不包括
statusCode
headers
,它只使用整个返回对象作为响应主体

除此之外,.yml中配置的头也没有被使用

这似乎是一个非常愚蠢的错误,但我只是在做一些事情


因此,我的问题是:如何正确配置响应属性,以便HTTP请求使用无服务器框架给出正确的响应?

您需要将lambda函数配置为作为lambda代理事件调用


请参见

我认为您需要将集成配置为
lambda代理
,而不是lambda。