I have a .NET Lambda function written in C#, implemented as a .NET Mimimal API with (as described here). I am using the CDK (TypeScript) to define the AWS resources.
The build pipeline includes shell scripting to pass in a parameter to define the stage (i.e., dev vs. qa vs. beta vs. prod) as follows:
cdk synth -c "stage=${StageName}"
In my CDK code, I read this variable as follows:
const stage = this.node.tryGetContext('stage');
This is used to then determine which environment-specific settings to use in cdk.json
when defining the stack (endpoints, etc.).
My question is: is there a way to pass this variable into the Lambda function’s startup logic? I know that I can pass it into the body of the Lambda function itself as a parameter. But I really need to be able to pass it into the app startup logic that gets executed before the function body is entered (i.e. when I’m telling the configuration logic which appsettings.{env}.json
to use).
Is this possible via the CDK?