amazon-web-services - ALB 未正确传播响应 header

标签 amazon-web-services aws-lambda aws-alb

我在 ALB 后面有一个 lambda 目标。我的 lambda 是一个 python lambda。

def handler(event, context):
response = {
    "statusCode": 200,
    "statusDescription": "200 OK",
    "isBase64Encoded": False,
    "headers": {
        "Content-Type": "text/html; charset=utf-8"
    }
}

不过,在使用 curl 访问我的 url 时,我收到了一个
< HTTP/1.1 200 OK
< Server: awselb/2.0
< Date: Sat, 06 Apr 2019 04:46:50 GMT
< Content-Type: application/octet-stream
< Content-Length: 0
< Connection: keep-alive

备注 Content-Type是一个八位字节流,它导致浏览器将响应下载为文件而不是显示它。我尝试添加其他标题 "Foo":"Bar"响应,它们不会出现在 curl 响应中。 ALB 似乎正在吃我的 lambda 提供的 header 。我怎样才能解决这个问题?

最佳答案

原来我为我的目标组打开了多值标题。启用该设置后,我的 lambdas 需要返回包含字段 multiValueHeaders 的响应。设置而不是 headers .所以我的 lambda 代码需要是:

def handler(event, context):
response = {
    "statusCode": 200,
    "statusDescription": "200 OK",
    "isBase64Encoded": False,
    "multiValueHeaders": {
        "Content-Type": ["text/html; charset=utf-8"]
    }
}
更多信息 on AWS' release blog post .

关于amazon-web-services - ALB 未正确传播响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55546026/

相关文章:

amazon-web-services - 将 protobuf 与 Amazon IoT 结合使用

Kubernetes ALB 入口 : How to expose multiple ports on ingress resource

kubernetes - "services is forbidden: User\"系统 :serviceaccount:tick:external-dns\"cannot list resource\"services\"in API group\"\"at the cluster scope"

swift - 为 swift iOS 应用程序安装 cocoa pod 后找不到名为 AWSLex 的模块

android - 将数据库从云端下载到 Android

security - AWS CLI : The role defined for the function cannot be assumed by Lambda

postgresql - 构建 lambda 函数以连接到 Postgresql 获取 :Unable to import module 'lambda_function' : No module named 'psycopg2'

amazon-web-services - AWS : Amazon Cognito vs STS and SAML

amazon-web-services - AWS CloudWatch过滤带有@的紧凑json

node.js - 当从 Nodejs 中的 Lambda 返回音频缓冲区时,AWS ALB 返回 502 Bad Gateway