Repository navigation
Closed
Description
Description:
When returning the response from a Lambda function to the client Envoy sets the 'content-type' header to 'application/json' instead of the content-type set by the Lambda. It seems the aws-lambda extension is pulling the content-type from the aws lambda api connection (line 351 in aws_lambda_filter.cc)
Repro steps:
Create a Lambda function that responds with content-type = 'text/html' or anything other than 'application/json'. Enable the aws-lambda extension with payload_passthrough = false.
Config:
admin:
address:
socket_address: { address: 127.0.0.1, port_value: 9901 }
static_resources:
listeners:
- address:
socket_address: { address: 0.0.0.0, port_value: 443 }
filter_chains:
- transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
common_tls_context:
tls_certificates:
- certificate_chain:
filename: "/etc/xx/xx/default.crt"
private_key:
filename: "/etc/x/xx/default.key"
filters:
- name: envoy.extenstions.filters.network.http_connection_manager.v3
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
stat_prefix: http
use_remote_address: true
server_header_transformation: OVERWRITE
strip_any_host_port: true
http2_protocol_options:
max_concurrent_streams: 100
access_log:
name: envoy.file_access_log
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /var/log/envoy/access.log
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: lambda_egress_gateway }
http_filters:
- name: envoy.filters.http.compressor
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
response_direction_config:
common_config:
min_content_length: 100
content_type:
- text/html
- application/json
disable_on_etag_header: true
request_direction_config:
common_config:
enabled:
default_value: false
runtime_key: request_compressor_enabled
compressor_library:
name: text_optimized
typed_config:
"@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
memory_level: 3
window_bits: 10
compression_level: best_compression
compression_strategy: default_strategy
- name: envoy.filters.http.aws_lambda
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.aws_lambda.v3.Config
arn: "arn:aws:lambda:us-west-1:062333172176:function:xxxx-myfunction-xxxx"
payload_passthrough: false
- name: envoy.filters.http.router
clusters:
- name: lambda_egress_gateway
connect_timeout: 0.55s
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
metadata:
filter_metadata:
com.amazonaws.lambda:
egress_gateway: true
load_assignment:
cluster_name: lambda_egress_gateway
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: lambda.us-west-1.amazonaws.com
port_value: 443
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
sni: "*.amazonaws.com"
Logs:
Activity
rgs1 commentedon May 24, 2021
cc: @marcomagdy @jstewmon
jstewmon commentedon May 24, 2021
I think the call to
headers.setReferenceContentTypeindejsonizeResponsejust need to be moved above the iteration of the json response headers, so that the default content type isapplication/jsonunless the json response headers field has acontent-typekey:envoy/source/extensions/filters/http/aws_lambda/aws_lambda_filter.cc
Lines 336 to 351 in 8db01a4
marcomagdy commentedon May 24, 2021
Ifpassthroughis set tofalse, then the request and the response are assumed to be JSON. For any othercontent-typesetpassthroughtotrue.jstewmon commentedon May 24, 2021
@marcomagdy is there some reason the filter should not use the
content-typeheader from the response? From the filter docs:I haven't used this filter myself, but just reviewing the docs and the implementation, it looks like a bug that the content-type of the response is always set to
application/jsoneven when the JSON response from the lambda specifies a differentcontent-type.marcomagdy commentedon May 24, 2021
Yes, I think you're right.
It's been a long time, so the details elude me sometimes.