amazon-web-services - 如何使用AWS API Gateway从URL中剥离参数?

标签 amazon-web-services aws-lambda aws-api-gateway

我使用 GET 创建了 /redirect 方法,我想将带有参数的 URL 传递给它,如下所示:

/redirect/https://example.com?param=1

然后,剥离参数并通过重定向响应:

https://example.com

这是一种非常不寻常的情况,因为我发现大多数 API 请求都传递 URL 参数,而我打算采取相反的做法。我很矛盾是否应该使用 Mock 还是 Lambda。

有人能指出我正确的方向吗?

谢谢。

最佳答案

我认为您可能希望将 URL 作为查询字符串参数而不是路径参数传递。我认为它看起来像这样:

GET/redirect?uri=https://example.com?param=1

exports.handler = async (event, context) => {
  const Location = decodeURIComponent(event.queryStringParameters.uri);
  return {
    statusCode: 302,
    headers: { Location },
  }
};

这应该返回 302 Found响应重定向位置,这应该会导致浏览器重定向。

关于amazon-web-services - 如何使用AWS API Gateway从URL中剥离参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55880653/

相关文章:

spring - 在 Amazon Beanstalk 上处理 Spring Boot 集群 Websocket

amazon-web-services - aws 批处理 : submit job using lambda

php - Laravel amazon ses 给出 Swift_TransportException

python - AWS python Lambda 无法访问 EFS 文件

amazon-web-services - 将 ASP.NET Core Web API 发布到 AWS Serverless Lambda : 'AWSLambdaFullAccess' at 'policyArn' . 时出错.. 成员的长度必须大于

api - 亚马逊 API 网关的 OAuth

node.js - AWS Lambda 函数可以调用另一个函数吗

node.js - 从 AWS lambda 函数写入 dynamodb

node.js - AWS 无服务器 - 自动创建 DynamoDB

amazon-web-services - S3 与 EBS 性能