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.
On 'Method Request' > 'URL Query String Parameters' I set it up the name 'customerIdentification'
Then as the documentation says: doc
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.
", request.RequestContext.RequestID)
fmt.Printf("Body size = %d.
", len(request.Body))
fmt.Println("Headers:")
for key, value := range request.Headers {
fmt.Printf(" %s: %s
", 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)
}
I expect that on the golang lambda function code I can retrieve the 'userId' from 'request.Headers'.
but it always come empty
To retrieve a value for any key from map in golang you can simply do like this
val, ok := request.Headers["userId"]
if ok { // the key is present
fmt.Println(val)
}
But are you sure, the key 'userId' is in header? usually these kind of keys will be in body only. If you want to cross check try to unmarshal your request.Body into map[string]string and retrieve "userd" from there.
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...