serverless-next.js
serverless-next.js copied to clipboard
Ability to configure the API Lambda@Edge in the NextJSLambdaEdge construct
Is your feature request related to a problem? Please describe. I want an elegant way to pass secrets or other configurations into the API Lambda@Edge. Due to limitations, environment variables are not supported.
Describe the solution you'd like
I'd like to be able to supply an object to the NextJSLambdaEdge
construct like this,
const nextApp = new NextJSLambdaEdge(this, `${id}Edge`, {
...,
apiConfig: {
hCaptchaKey: process.env.BUILD_ENV_VAR,
stage: process.env.STAGE,
gitCommit: process.env.GIT_COMMIT,
}
});
Describe alternatives you've considered
I've considered just creating a configuration file at build time using CDK that would be placed in the /pages/api
, but seems a bit clunky and I'm not sure what the implications of doing this would be.
I've considered using CloudFront headers to set my configuration variables, but it feels convoluted and a bit confusing to figure out.
Additional context I found this package which implements this: @henrist/cdk-lambda-config
Hi @coltenkrauter ,
I'm not sure if it's any help, I was just browsing and spotted your issue, but I have done something similar. It's similar to the approach you've described where you've considered building a config file at build time, so it might still seem clunky.
In my CI at build time I use jinja templating to build a .env.local
file which is picked up by NextJS during the serverless build.