Environment variables in CDK construct
See original GitHub issueIssue Summary
I struggle to pass CDK values into the builder for Next to use them as environment variables.
Actual behavior
Values come across as CDK tokens:
env: {
REGION: '${Token[AWS.Region.6]}'
}
Expected behavior
CDK values to be resolved and embedded into Next env correctly.
Steps to reproduce
Pass values from other CDK constructs (e.g. Function ARN or region) around as props and then pass them to the Builder
env
options.
Additional Context
I’ve read the discussion in https://github.com/serverless-nextjs/serverless-next.js/issues/184, but it seems not applicable to the CDK construct. It seems a CDK specific issue.
Checklist
- You have reviewed the README and FAQs, which answers several common questions.
- You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if possible.
- You have first tried using the most recent
latest
oralpha
@sls-next/serverless-component
release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the oldserverless-next.js
component and theserverless-next.js
plugin are deprecated and no longer maintained.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Environments - AWS Cloud Development Kit (AWS CDK) v2
In an environment-agnostic stack, any constructs that use Availability Zones ... your stack can use two environment variables provided by the AWS CDK...
Read more >CDK context and Environment | Keep bragging - Technologies
CDK context and Environment. In CDK deployment, it is important to retrieve context and environment variables such as stage, region, user, account, etc....
Read more >How to use Environment Variables in AWS CDK | bobbyhadz
In order to use environment variables in AWS CDK we have to first set them using the CDK CLI and then access them...
Read more >Adding environment variables to the Lambda function using ...
In this blog, we will learn how to add environment variables to the Lambda function using CDK. We have learned how to create...
Read more >How to set environment variable for Lambda using CDK
In the previous post, I show how to make a Lambda function using CDK. In this post, I will show we can set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It does not work for Lambda@Edge as env variables are not supported. Soooo
slsNext.defaultNextLambda.addEnvironment
is not gonna cut it.For now, what works for me is going for
printenv > .env
during build time. This setsprocessEnv
vars inoutput/api-lambda/pages/*
.Downside it’s populated for all functions, so in theory, it might be accessible from outside the API, possibly revealing secrets (have not figure out how to pen test it tho).
Hope it helps.
PS. I’m kinda getting pissed at this Edge limitations and deployment speeds. It really feels like having normal Lambda would be easier to grasp.
@shishkin
NextJSLambdaEdge
has some member variables that holds lambda function construct. https://github.com/serverless-nextjs/serverless-next.js/blob/master/packages/serverless-components/nextjs-cdk-construct/src/index.ts#L56-L60so, for example…