通过 AWS Lambda 重定向 URL
Redirect URL through AWS Lambda
我正在尝试跟踪打开的电子邮件。我使用 AWS API 网关和 Lambda 作为后端,并通过附加到电子邮件的 1x1 像素进行跟踪。
目前我的 lambda 函数只是 returns 我要重定向到的实际图像的位置。一旦重定向正常运行(电子邮件跟踪),我将使用此 lambda 函数向我的数据库添加一个计数器增量:
def handler(event, context):
Location = 'https://s3-eu-west-1.amazonaws.com/stylezz.biz/email-sig/1.png'
return Location
在我的 API 网关中,我已将响应设置为 301,并将 lambda 函数的输出映射到我的位置 header。然而 URL 并不会简单地重定向 returns JSON 格式的位置。:
任何人都知道我如何才能真正让 API 重定向
1) 定义状态为 302 的方法响应,以及定义的“位置”header
2) 使用空白正则表达式定义“默认”集成响应映射,映射到 302.
3) 对于此响应,从您的 Lambda 函数中的重定向 URL return 定义一个“位置”header 映射。即“integration.response.body.location”
3) 将您的 lambda 函数配置为 return body 中的重定向位置,即
招摇的例子:
/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
我正在尝试跟踪打开的电子邮件。我使用 AWS API 网关和 Lambda 作为后端,并通过附加到电子邮件的 1x1 像素进行跟踪。
目前我的 lambda 函数只是 returns 我要重定向到的实际图像的位置。一旦重定向正常运行(电子邮件跟踪),我将使用此 lambda 函数向我的数据库添加一个计数器增量:
def handler(event, context):
Location = 'https://s3-eu-west-1.amazonaws.com/stylezz.biz/email-sig/1.png'
return Location
在我的 API 网关中,我已将响应设置为 301,并将 lambda 函数的输出映射到我的位置 header。然而 URL 并不会简单地重定向 returns JSON 格式的位置。:
任何人都知道我如何才能真正让 API 重定向
1) 定义状态为 302 的方法响应,以及定义的“位置”header
2) 使用空白正则表达式定义“默认”集成响应映射,映射到 302.
3) 对于此响应,从您的 Lambda 函数中的重定向 URL return 定义一个“位置”header 映射。即“integration.response.body.location”
3) 将您的 lambda 函数配置为 return body 中的重定向位置,即
招摇的例子:
/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