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 🙏
gentle-planet-18535
10/30/2024, 8:52 PM
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
happy-autumn-40938
11/01/2024, 5:10 PM
handleRequest()
isn't supposed to return anything (unless you set
env.returnResponse = true;
). Instead its mean to call in internal callback.
g
gentle-planet-18535
11/02/2024, 4:52 PM
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
happy-autumn-40938
11/03/2024, 4:54 AM
yeah its a bit confusing. its a conditionally async function since we wanted to support both use cases