我正在尝试跟踪打开的电子邮件。我使用 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 格式的位置:
任何人都知道我如何才能真正获得 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/