.htaccess - 通过 AWS Lambda 重定向 URL

标签 .htaccess amazon-web-services redirect aws-lambda

我正在尝试跟踪打开的电子邮件。我使用 AWS API 网关和 Lambda 作为后端,并通过附加到电子邮件的 1x1 像素进行定位。

目前,我的 lambda 函数只是返回我想要重定向到的实际图像的位置。一旦重定向起作用(电子邮件跟踪),我将使用此 lambda 函数向我的数据库添加计数器增量:

def handler(event, context):
Location = 'https://s3-eu-west-1.amazonaws.com/stylezz.biz/email-sig/1.png'
return Location

在我的 API 网关中,我将响应设置为 301 并将 lambda 函数的输出映射到我的 Location header 。然而,URL 不会重定向,只是返回 JSON 格式的位置: enter image description here

任何人都知道我如何才能真正获得 API 进行重定向

最佳答案

1) 定义状态为 302 的方法响应,并定义“Location” header
2) 使用空白正则表达式定义“默认”集成响应映射,映射到 302。
3) 对于此响应,从 Lambda 函数中返回的重定向 URL 定义“位置” header 映射。即“integration.response.body.location”
3) 配置 lambda 函数以返回正文中的重定向位置,即

招摇示例:

/lambdaredirect-default:
    get:
      produces:
      - "application/json"
      parameters: []
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
          headers: {}
        302:
          description: "302 response"
          headers:
            Location:
              type: "string"
      x-amazon-apigateway-integration:
        responses:
          default:
            statusCode: "302"
            responseParameters:
              method.response.header.Location: "integration.response.body.location"
        uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:[ACCOUNT_ID]:function:redirect-default/invocations"
        httpMethod: "POST"
        type: "aws"

lambda 函数

exports.handler = function(event, context) {
    context.succeed({
        location : "https://example.com"
    });
};

了解更多 here

关于.htaccess - 通过 AWS Lambda 重定向 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36246694/

相关文章:

database - 端口重定向不起作用 (80->3306)

php - 如何在 Apache 中访问一个文件夹?

javascript - 如何在 2 个 JSON 文件之间插入匹配 JSON 键的值

javascript - GAS(谷歌应用程序脚本)/Google Drive API : Retrieving a redirected URL from pre redirect link

amazon-web-services - 如何在 AWS CloudFront 中配置查询参数

python - botocore.exceptions.ClientError : An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

unit-testing - 具有副作用的单元测试功能?

wordpress - 403 禁止 : permission to access images

php - 如果端口不是 80,.htaccess 重定向到错误页面

php - 使用动态 URL 的 Htaccess 301 重定向