【发布时间】:2019-11-20 22:21:55
【问题描述】:
简要概述。
我在 S3 存储桶上托管一个 Angular 应用程序。我还有一个 Cloudfront 分发版来处理 HTTPS 和重定向。
我尝试根据用户连接的 URL 形成一个查询字符串参数。
2 个例子
test.example.com --> example.com?id=test
hello.example.com --> example.com?id?hello
到目前为止,我尝试实现一个 AWS lambda@Edge 函数,但到目前为止没有任何效果。如果我尝试操纵 request 它不会有任何影响,如果我尝试操纵 response 重定向不起作用并且我收到 S3 存储桶错误或 Cloudfront 错误。
'use strict';
const remove_suffix = '.example.com';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
const host_header = headers.host[0].value;
if(host_header.endsWith(remove_suffix)){
request.querystring = 'id=' + host_header.substring(0,host_header.length - remove_suffix.length);
}
return callback(null,request);
};
1) 我应该使用哪个触发器?
2) Cloudfront 设置中可能缺少哪些设置?
3) 我的 Lambda 函数错了吗?
【问题讨论】:
标签: angular amazon-web-services aws-lambda amazon-cloudfront aws-lambda-edge