在初始化容器之后(从处理程序功能中),是否有一种方法可以更新数据库凭证? 我必须从AWS Secrets Manager中读取数据库密码并更新数据源。但是,当我从StreamLambdaHandler构造函数执行此操作时,它超出了初始化的时间限制(〜10s)。
public class StreamLambdaHandler implements RequestStreamHandler {
private static Logger log = LoggerFactory.getLogger(Application.class);
private static MicronautLambdaContainerHandler handler; // <1>
DBCredentialService dbCredentialService;
ApplicationContextBuilder builder;
public StreamLambdaHandler() {
try {
log.info("********ContainerInitialization**************");
this.dbCredentialService = new DBCredentialService();
// Get database credential properties from secrets manager
Map<String, Object> props = this.dbCredentialService.getDbCredential();
// Update the datasource properties
// E.g. "datasources.default.password", "sample_password"
builder = ApplicationContext.build().properties(props);
handler = new MicronautLambdaContainerHandler(builder);
} catch (Exception e) {
log.info("ContainerInitializationException " + e.getMessage());
// if we fail here. We re-throw the exception to force another cold start
e.printStackTrace();
throw new RuntimeException("Could not initialize Micronaut", e);
}
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
this.log.info("Starting handler.proxyStream");
handler.proxyStream(inputStream, outputStream, context); // <2>
}
}