Open sdelamo opened 3 years ago
If micronaut-projects/micronaut-core#6077 gets merged, I plan to change LambdaApplicationContextBuilder
to:
public class LambdaApplicationContextBuilder extends DefaultApplicationContextBuilder {
public LambdaApplicationContextBuilderReplacement() {
setLambdaConfiguration(this);
}
public static void setLambdaConfiguration(ApplicationContextBuilder builder) {
Boolean deduceEnvironment = (applicationContextBuilder instanceof DefaultApplicationContextBuilder) ?
((DefaultApplicationContextBuilder) applicationContextBuilder).getDeduceEnvironments().orElse(null) : null
if (DefaultEnvironment.shouldDeduceEnvironment(deduceEnvironment)) {
builder = builder.environments(Environment.FUNCTION, MicronautLambdaContext.ENVIRONMENT_LAMBDA);
}
builder.eagerInitConfiguration(true)
.eagerInitSingletons(true);
}
...
..
.
Steps To Reproduce
Create a Lambda function with the following environment variables:
MICRONAUT_ENVIRONMENTS
toec2
MICRONAUT_ENV_DEDUCTION
tofalse
Expected Behavior
I expected environment to be just
ec2
Actual Behaviour
environments are
ec2
cloud
function
lambda
Version
3.0.0
Workaround
A workaround is to create a class such as:
and in the handler override
MicronautRequestHandler::newApplicationContextBuilder