Standard library example bugged or unclear, response always text/plain
iancullinane opened this issue · comments
The example for the standard library seems to always return as text/plain
regardless of what I try. I have tried a few implementations, my recent attempt is below. Even when setting the header directly, the response header is always text/plain
.
The body is always correct (that is to say it is valid json in the body), it seems to only be the header. This is confusing compared to docs which seem to indicate this is inferred when the response has json. I can use the payload v2 type directly, but that feels cumbersome when this should (?) work.
Additionally when I test the lambda locally or in the lambda console, it works as expected.
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
response := map[string]string{"number": "five"}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
})
lambda.Start(httpadapter.New(http.DefaultServeMux).ProxyWithContext)
}
I am deploying this via cdk...
...
const lambda = new myLambda.DockerImageFunction(this, "ECRFunction", {
role: myLambda,
environment: {
CodeVersionString: this.sha,
},
code: lambda.DockerImageCode.fromEcr(repo, {
tag: this.sha,
}),
});
const myLambdaIntegration = new HttpLambdaIntegration(
"defaultIntergration",
myLambdaIntegration
);
const api = new apigwv2.HttpApi(this, "my-api", {
defaultDomainMapping: {
domainName: dn,
},
});
api.addRoutes({
path: "/v1/{proxy+}",
methods: [apigwv2.HttpMethod.ANY],
integration: myLambdaIntegration,
});
...