Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.
This repository was archived by the owner on May 21, 2025. It is now read-only.

Standard library example bugged or unclear, response always text/plain #116

@iancullinane

Description

@iancullinane

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,
    });
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions