0

我的 Lambda 函数返回 html 页面。我能够从节点 js 10.x 成功返回完整的 html。因此,如果我使用 api gateway url https://2kiz3ttah.execute-api.eu-west-1.amazonaws.com/stage/login访问我的 lambda, 如果未登录,则 lambda 应该返回一个重定向 URL。如何返回在浏览器中打开的 URL,而不是呈现 HTML 页面。

4

2 回答 2

4

我猜你有类似的东西:

// ...your code
return {
  statusCode: 200,
  headers: {
    'Content-Type': 'text/html',
  },
  body: html,
};

因此,根据您的自定义逻辑返回 3xx 应该很容易。如果您的问题是基于 cognito auth,那么我认为您不走运,因为它 api 网关会在您执行任何操作之前返回 403。在这种情况下,您可以尝试实现自定义 lambda 授权器,以便您可以实现自定义逻辑

于 2020-07-05T07:48:36.253 回答
3

在您的 Lambda 中,您只需要返回以下内容:

{
   'statusCode': 302,
   'headers': {
       'Location': 'https://redirect.example.com/path'
   }
}

https://redirect.exaaple.com/path您的路径应重定向到的 URL在哪里。

如果它是LAMBDA_PROXYAPI Gateway 中的集成,这应该适用于您的 Lambda。

更多信息可在此处获得。

于 2020-07-05T07:33:04.593 回答