Skip to content

Commit 5ec3c21

Browse files
committed
fix: cold start only on on-demand invocation
1 parent 93d302f commit 5ec3c21

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

powertools-common/src/main/java/software/amazon/lambda/powertools/common/internal/LambdaConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ private LambdaConstants() {
2828
public static final String ROOT_EQUALS = "Root=";
2929
public static final String POWERTOOLS_SERVICE_NAME = "POWERTOOLS_SERVICE_NAME";
3030
public static final String SERVICE_UNDEFINED = "service_undefined";
31+
public static final String AWS_LAMBDA_INITIALIZATION_TYPE = "AWS_LAMBDA_INITIALIZATION_TYPE";
32+
public static final String ON_DEMAND_INVOCATION_TYPE = "on-demand";
3133
}

powertools-common/src/main/java/software/amazon/lambda/powertools/common/internal/LambdaHandlerProcessor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ protected static void resetServiceName() {
9393
}
9494

9595
public static boolean isColdStart() {
96-
return isColdStart == null;
96+
if (isColdStart != null) {
97+
return isColdStart;
98+
}
99+
100+
String initType = System.getenv(LambdaConstants.AWS_LAMBDA_INITIALIZATION_TYPE);
101+
boolean cold = LambdaConstants.ON_DEMAND_INVOCATION_TYPE.equals(initType);
102+
103+
isColdStart = cold;
104+
return cold;
97105
}
98106

99107
public static void coldStartDone() {

0 commit comments

Comments
 (0)