API网关集成请求HTTP标头未将查询字符串映射到标头 [英] API-Gateway Integration Request HTTP Header not mapping query string to header

查看:96
本文介绍了API网关集成请求HTTP标头未将查询字符串映射到标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Api-Gateway上,我尝试设置从方法请求"查询字符串到集成请求"标头到lambda的映射,但是映射永远不会到达lambda函数.

On Api-Gateway i'm trying so set up mapping from 'Method Request' query string to 'integration request' headers to lambda but the mapping never reach the lambda function.

在方法请求">"URL查询字符串参数"上,我将其设置为"customerIdentification"

On 'Method Request' > 'URL Query String Parameters' I set it up the name 'customerIdentification'

然后如文档所述:文档

转到集成请求">"HTTP标头"添加名称"userId"并映射到"method.request.querystring.customerIdentification"

went to 'Integration Request' > 'HTTP Headers' add a name 'userId' and mapped to 'method.request.querystring.customerIdentification'

package main

import (
    "context"
    "encoding/json"
    "fmt"

    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
)

func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {

    fmt.Printf("Processing request data for request %s.\n", request.RequestContext.RequestID)
    fmt.Printf("Body size = %d.\n", len(request.Body))

    fmt.Println("Headers:")
    for key, value := range request.Headers {
        fmt.Printf("    %s: %s\n", key, value)
    }
    xxx, err := json.Marshal(request.Headers)
    if err != nil {
        fmt.Println("*** err *** err *** err *** err *** err ")
        fmt.Println(err)
        fmt.Println("*** err *** err *** err *** err *** err ")
    }
    return events.APIGatewayProxyResponse{Body: string(xxx), StatusCode: 200}, nil
}

func main() {
    lambda.Start(handleRequest)
}

我希望在golang lambda函数代码上,我可以从'request.Headers'中检索'userId'.

I expect that on the golang lambda function code I can retrieve the 'userId' from 'request.Headers'.

但它总是空的

推荐答案

与您有相同的问题,我认为仅当您使用http或aws服务代理时,才会转发Http标头,如本文档所示 https://docs. aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings-execution-console.html

I have the same issue with you, I think the Http Headers will only forwarded if you use http or aws service proxy as shown in this document https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings-execution-console.html


For an HTTP proxy or an AWS service proxy, to associate a path parameter, a query string parameter, or a header parameter defined in the integration request with a corresponding path parameter, query string parameter, or header parameter in the method request of the HTTP proxy or AWS service proxy, do the following...

这篇关于API网关集成请求HTTP标头未将查询字符串映射到标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆