Monitor Lambda cold start durations with CloudWatch
When you look at an X-Ray trace for a Lambda cold start, you will see an Initialization subsegment. This subsegment represents “the function’s initialization code that is run before the handler”. This is where the runtime would resolve any dependencies, or initialize global variables. These are executed only once, so they don’t have to run on every invocation. The more dependencies you have, the longer this initialization step takes.