I would use the @ConditonalOnProperty annotation here on two configs, and add the properties in the main of one of the runtimes , take for example lambda (since you said each run uses a different one)
public static void main(String[] args) {
SpringApplication application = new SpringApplication(DemoApplication.class);
Properties properties = new Properties();
properties.put("lambda.application", "true");
application.setDefaultProperties(properties);
application.run(args);
}
then on the config needed when run time is lambda you can annotate the bean as such
@ConditionalOnProperty(
value="lambda.application",
havingValue = "true")
public class DyanmoConfig {
Then the other bean could have the following conditional properties
@ConditionalOnProperty(
value="lambda.application",
havingValue = "false",
matchIfMissing= true)
public class PersistConfig {
This way you only need to set the properties programatically in one of the two main's