Hi there :slightly_smiling_face: Did someone have ...
# ask-questions
g
Hi there 🙂 Did someone have already implemented growthbook/edge-lambda using Lambda@Edge ? It seems that my lambda zip which imports only the edge-lambda package exceeds the restriction of 1 MB by 0.3 MB. I am only interested in URL Redirection experiment, is there a way to tree-shake this package ? Any clue ? I tried to use Layers but cannot use them with CloudFront. Thank you 🙏
I managed to minify the bundle so my lambda function goes under 1 MB. But now, I'm getting a
502 The Lambda function returned invalid JSON: The JSON output must be an object type
. Looks like the
handlerRequest
from
@growthbook/edge-lambda
returns
null
I am using this snippet:
Copy code
import { handleRequest } from "@growthbook/edge-lambda";

export async function handler(event, ctx, callback) {
  // Manually build your environment:
  const env = buildEnv();

  // Specify additional edge endpoint information:
  env.host = "<http://www.mysite.io|www.mysite.io>";

  // Uncomment for ease of testing locally - returns response instead of using callback():
  // env.returnResponse = true;

  handleRequest(event, callback, env);
}

function buildEnv() {
  // todo: define environment variables here
}
I just added my build env and set env.host.
h
handleRequest()
isn't supposed to return anything (unless you set
env.returnResponse = true;
). Instead its mean to call in internal callback.
g
Well it seemed to be a pure JS issue, since handleRequest is async, the handler actually returned
null
. Returning the promise solved this issue
h
yeah its a bit confusing. its a conditionally async function since we wanted to support both use cases