Kong lambda 插件 - 关联 ID 被删除
Kong lambda plugin - Correlation id being dropped
所以我使用 kong 作为 API 网关。我在 aws 上有一个简单的 lambda 函数返回 headers。我能够看到来自 aws lambda 函数的响应,但是没有关联 ID。我已将 correlation-id 插件设置为全局。想澄清一下为什么 lambda 插件没有在原始响应的 headers 中添加 correlation-id。
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify(event.request_headers),
};
return response;
};
我的kong.yaml
_format_version: "1.1"
routes:
- name: lambda1
paths:
- /lambda1
path_handling: v0
preserve_host: false
protocols:
- http
- https
regex_priority: 0
strip_path: true
https_redirect_status_code: 426
plugins:
- name: aws-lambda
config:
aws_key: XXXXXXXXXXXXXXXXXXXXXXX
aws_region: us-east-1
aws_secret: XXXXXXXXXXXXXXXXXXXXXXXXx
awsgateway_compatible: false
forward_request_body: true
forward_request_headers: true
forward_request_method: false
forward_request_uri: false
function_name: kong-lambda-plugin
host: null
invocation_type: RequestResponse
is_proxy_integration: false
keepalive: 60000
log_type: Tail
port: 443
proxy_scheme: null
proxy_url: null
qualifier: null
skip_large_bodies: true
timeout: 60000
unhandled_status: null
enabled: true
protocols:
- grpc
- grpcs
- http
- https
plugins:
- name: correlation-id
config:
echo_downstream: false
generator: uuid#counter
header_name: correlation-id
enabled: true
protocols:
- grpc
- grpcs
- http
- https
你是对的,问题来自插件优先级
CorrelationIdHandler.PRIORITY = 1
AWSLambdaHandler.PRIORITY = 750
Aws Lambda 插件正在打破插件链,就像它在处理程序阶段所做的那样
return kong.response.exit(status, content, headers)
所以其他插件无法使用
您可以创建自定义 correlationId 插件并更改优先级,有一个工具可以为您处理 https://github.com/Kong/priority-updater
您还可以创建一个路由来添加关联 ID,调用另一个执行 lambda 调用的路由
所以对我有用的是
https://github.com/Kong/priority-updater
- 我创建了由上面的脚本生成的 .rock 文件。
- 因为我使用的是 docker 化版本的 Kong,所以我将文件复制到我的 Kong docker 主机上。
- 使用 luarocks 命令在我的 Kong docker 主机上安装了插件。
- 已将插件添加到我的 'kong.conf' 文件中。
- 将其添加到 lambda 路由中,效果非常好。
所以我使用 kong 作为 API 网关。我在 aws 上有一个简单的 lambda 函数返回 headers。我能够看到来自 aws lambda 函数的响应,但是没有关联 ID。我已将 correlation-id 插件设置为全局。想澄清一下为什么 lambda 插件没有在原始响应的 headers 中添加 correlation-id。
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify(event.request_headers),
};
return response;
};
我的kong.yaml
_format_version: "1.1"
routes:
- name: lambda1
paths:
- /lambda1
path_handling: v0
preserve_host: false
protocols:
- http
- https
regex_priority: 0
strip_path: true
https_redirect_status_code: 426
plugins:
- name: aws-lambda
config:
aws_key: XXXXXXXXXXXXXXXXXXXXXXX
aws_region: us-east-1
aws_secret: XXXXXXXXXXXXXXXXXXXXXXXXx
awsgateway_compatible: false
forward_request_body: true
forward_request_headers: true
forward_request_method: false
forward_request_uri: false
function_name: kong-lambda-plugin
host: null
invocation_type: RequestResponse
is_proxy_integration: false
keepalive: 60000
log_type: Tail
port: 443
proxy_scheme: null
proxy_url: null
qualifier: null
skip_large_bodies: true
timeout: 60000
unhandled_status: null
enabled: true
protocols:
- grpc
- grpcs
- http
- https
plugins:
- name: correlation-id
config:
echo_downstream: false
generator: uuid#counter
header_name: correlation-id
enabled: true
protocols:
- grpc
- grpcs
- http
- https
你是对的,问题来自插件优先级
CorrelationIdHandler.PRIORITY = 1
AWSLambdaHandler.PRIORITY = 750
Aws Lambda 插件正在打破插件链,就像它在处理程序阶段所做的那样
return kong.response.exit(status, content, headers)
所以其他插件无法使用
您可以创建自定义 correlationId 插件并更改优先级,有一个工具可以为您处理 https://github.com/Kong/priority-updater
您还可以创建一个路由来添加关联 ID,调用另一个执行 lambda 调用的路由
所以对我有用的是
https://github.com/Kong/priority-updater
- 我创建了由上面的脚本生成的 .rock 文件。
- 因为我使用的是 docker 化版本的 Kong,所以我将文件复制到我的 Kong docker 主机上。
- 使用 luarocks 命令在我的 Kong docker 主机上安装了插件。
- 已将插件添加到我的 'kong.conf' 文件中。
- 将其添加到 lambda 路由中,效果非常好。