Execution environment reuse and cold starts
Code outside the handler runs once per cold start and persists across warm invocations of the same environment, so connections and rarely-changing config belong there rather than in the handler. SnapStart resumes from a snapshot of an already-initialised environment, cutting init time without Provisioned Concurrency's ongoing cost; Provisioned Concurrency pre-initialises environments outright and is the answer when a synchronous path cannot tolerate cold starts. The context object's getRemainingTimeInMillis() lets the code decide whether there is time to attempt more work.