Skip to content

Commit ddb3445

Browse files
M-ElsaeedMohammed Ehab
authored andcommitted
Allow AWS_LAMBDA_MAX_CONCURRENCY to be one and crash the RIC Otherwise and Version Bump to 2.8.2 (#92)
* Allow AWS_LAMBDA_MAX_CONCURRENCY to be one and crash the RIC Otherwise. * Version Bump to 2.8.2 --------- Authored-by: Mohammed Ehab <moehabe@amazon.com>
1 parent e35157b commit ddb3445

File tree

7 files changed

+51
-29
lines changed

7 files changed

+51
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ The purpose of this package is to allow developers to deploy their applications
163163
<dependency>
164164
<groupId>com.amazonaws</groupId>
165165
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
166-
<version>2.8.1</version>
166+
<version>2.8.2</version>
167167
</dependency>
168168
```
169169

aws-lambda-java-runtime-interface-client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pom.xml
7070
<dependency>
7171
<groupId>com.amazonaws</groupId>
7272
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
73-
<version>2.8.1</version>
73+
<version>2.8.2</version>
7474
</dependency>
7575
</dependencies>
7676
<build>

aws-lambda-java-runtime-interface-client/RELEASE.CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### June 26, 2025
2+
`2.8.2`
3+
- Allow AWS_LAMBDA_MAX_CONCURRENCY to be One. Crash the RIC if it is set to an un-parsable string to an integer or an out of bounds value.
4+
15
### June 26, 2025
26
`2.8.1`
37
- Refactoring

aws-lambda-java-runtime-interface-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.amazonaws</groupId>
66
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
7-
<version>2.8.1</version>
7+
<version>2.8.2</version>
88
<packaging>jar</packaging>
99

1010
<name>AWS Lambda Java Runtime Interface Client</name>

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/ReservedRuntimeEnvironmentVariables.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public interface ReservedRuntimeEnvironmentVariables {
108108
String TZ = "TZ";
109109

110110
/*
111-
* Used to set the required number of concurrent runtime loops,
112-
* If AWS_LAMBDA_MAX_CONCURRENCY is not set, the default number of concurrent runtime loops is the number of cores.
111+
* If set to a string parsable as an integer > 0, It enables multiconcurrency mode.
112+
* Otherwise, if it is set to an invalid value, it will crash the whole RIC process.
113113
*/
114114
String AWS_LAMBDA_MAX_CONCURRENCY = "AWS_LAMBDA_MAX_CONCURRENCY";
115115
}

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/util/ConcurrencyConfig.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
public class ConcurrencyConfig {
1515
private static final int AWS_LAMBDA_MAX_CONCURRENCY_LIMIT = 1000;
1616
private final int numberOfPlatformThreads;
17+
private final String INVALID_CONFIG_MESSAGE_PREFIX = String.format("User configured %s is invalid. Please make sure it is a positive number more than zero and less than or equal %d",
18+
ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY, AWS_LAMBDA_MAX_CONCURRENCY_LIMIT);
1719

1820
public ConcurrencyConfig(LambdaContextLogger logger) {
1921
this(logger, new EnvReader());
@@ -24,21 +26,16 @@ public ConcurrencyConfig(LambdaContextLogger logger, EnvReader envReader) {
2426
try {
2527
String readLambdaMaxConcurrencyEnvVar = envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY);
2628

27-
// Log only if env var is actually set to an invalid value. Otherwise default to no concurrency silently.
28-
if (!(readLambdaMaxConcurrencyEnvVar == null || readLambdaMaxConcurrencyEnvVar.isEmpty())) {
29+
if (readLambdaMaxConcurrencyEnvVar != null) {
2930
readNumOfPlatformThreads = Integer.parseInt(readLambdaMaxConcurrencyEnvVar);
30-
if (readNumOfPlatformThreads <= 0 || readNumOfPlatformThreads > AWS_LAMBDA_MAX_CONCURRENCY_LIMIT) {
31+
if (readNumOfPlatformThreads < 1 || readNumOfPlatformThreads > AWS_LAMBDA_MAX_CONCURRENCY_LIMIT) {
3132
throw new IllegalArgumentException();
3233
}
3334
}
3435
} catch (Exception e) {
35-
readNumOfPlatformThreads = 0;
36-
String message = String.format(
37-
"User configured %s is not valid. Please make sure it is a positive number more than zero and less than or equal %d\n%s\nDefaulting to no concurrency.",
38-
ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY,
39-
AWS_LAMBDA_MAX_CONCURRENCY_LIMIT,
40-
UserFault.trace(e));
41-
logger.log(message, logger.getLogFormat() == LogFormat.JSON ? LogLevel.WARN : LogLevel.UNDEFINED);
36+
String message = String.format("%s\n%s", INVALID_CONFIG_MESSAGE_PREFIX, UserFault.trace(e));
37+
logger.log(message, logger.getLogFormat() == LogFormat.JSON ? LogLevel.ERROR : LogLevel.UNDEFINED);
38+
throw e;
4239
}
4340

4441
this.numberOfPlatformThreads = readNumOfPlatformThreads;
@@ -49,7 +46,7 @@ public String getConcurrencyConfigMessage() {
4946
}
5047

5148
public boolean isMultiConcurrent() {
52-
return this.numberOfPlatformThreads > 1;
49+
return this.numberOfPlatformThreads >= 1;
5350
}
5451

5552
public int getNumberOfPlatformThreads() {

aws-lambda-java-runtime-interface-client/src/test/java/com/amazonaws/services/lambda/runtime/api/client/util/ConcurrencyConfigTest.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import org.mockito.Mock;
1515
import org.mockito.junit.jupiter.MockitoExtension;
1616

17+
import static org.junit.Assert.assertThrows;
1718
import static org.junit.jupiter.api.Assertions.assertEquals;
18-
import static org.mockito.ArgumentMatchers.anyString;
19+
import static org.mockito.ArgumentMatchers.contains;
1920
import static org.mockito.ArgumentMatchers.eq;
2021
import static org.mockito.Mockito.*;
2122

@@ -27,6 +28,8 @@ class ConcurrencyConfigTest {
2728
@Mock
2829
private EnvReader envReader;
2930

31+
private static final String exitingRuntimeString = String.format("User configured %s is invalid.", ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY);
32+
3033
@Test
3134
void testDefaultConfiguration() {
3235
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn(null);
@@ -37,35 +40,51 @@ void testDefaultConfiguration() {
3740
assertEquals(false, config.isMultiConcurrent());
3841
}
3942

43+
@Test
44+
void testBelowMinPlatformThreadsLimit() {
45+
when(lambdaLogger.getLogFormat()).thenReturn(LogFormat.JSON);
46+
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("0");
47+
48+
assertThrows(IllegalArgumentException.class, () -> new ConcurrencyConfig(lambdaLogger, envReader));
49+
verify(lambdaLogger).log(contains(exitingRuntimeString), eq(LogLevel.ERROR));
50+
}
51+
52+
@Test
53+
void testMinValidPlatformThreadsConfig() {
54+
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("1");
55+
56+
ConcurrencyConfig config = new ConcurrencyConfig(lambdaLogger, envReader);
57+
verifyNoInteractions(lambdaLogger);
58+
assertEquals(1, config.getNumberOfPlatformThreads());
59+
assertEquals(true, config.isMultiConcurrent());
60+
}
61+
4062
@Test
4163
void testValidPlatformThreadsConfig() {
4264
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("4");
4365

4466
ConcurrencyConfig config = new ConcurrencyConfig(lambdaLogger, envReader);
67+
verifyNoInteractions(lambdaLogger);
4568
assertEquals(4, config.getNumberOfPlatformThreads());
4669
assertEquals(true, config.isMultiConcurrent());
4770
}
4871

4972
@Test
50-
void testInvalidPlatformThreadsConfig() {
73+
void testExceedingPlatformThreadsLimit() {
5174
when(lambdaLogger.getLogFormat()).thenReturn(LogFormat.JSON);
52-
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("invalid");
75+
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("1001");
5376

54-
ConcurrencyConfig config = new ConcurrencyConfig(lambdaLogger, envReader);
55-
assertEquals(0, config.getNumberOfPlatformThreads());
56-
verify(lambdaLogger).log(anyString(), eq(LogLevel.WARN));
57-
assertEquals(false, config.isMultiConcurrent());
77+
assertThrows(IllegalArgumentException.class, () -> new ConcurrencyConfig(lambdaLogger, envReader));
78+
verify(lambdaLogger).log(contains(exitingRuntimeString), eq(LogLevel.ERROR));
5879
}
5980

6081
@Test
61-
void testExceedingPlatformThreadsLimit() {
82+
void testInvalidPlatformThreadsConfig() {
6283
when(lambdaLogger.getLogFormat()).thenReturn(LogFormat.JSON);
63-
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("1001");
84+
when(envReader.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_MAX_CONCURRENCY)).thenReturn("invalid");
6485

65-
ConcurrencyConfig config = new ConcurrencyConfig(lambdaLogger, envReader);
66-
assertEquals(0, config.getNumberOfPlatformThreads());
67-
verify(lambdaLogger).log(anyString(), eq(LogLevel.WARN));
68-
assertEquals(false, config.isMultiConcurrent());
86+
assertThrows(NumberFormatException.class, () -> new ConcurrencyConfig(lambdaLogger, envReader));
87+
verify(lambdaLogger).log(contains(exitingRuntimeString), eq(LogLevel.ERROR));
6988
}
7089

7190
@Test
@@ -74,13 +93,15 @@ void testGetConcurrencyConfigMessage() {
7493

7594
ConcurrencyConfig config = new ConcurrencyConfig(lambdaLogger, envReader);
7695
String expectedMessage = "Starting 4 concurrent function handler threads.";
96+
verifyNoInteractions(lambdaLogger);
7797
assertEquals(expectedMessage, config.getConcurrencyConfigMessage());
7898
assertEquals(true, config.isMultiConcurrent());
7999
}
80100

81101
@Test
82102
void testGetConcurrencyConfigWithNoConcurrency() {
83103
ConcurrencyConfig config = new ConcurrencyConfig(lambdaLogger, envReader);
104+
verifyNoInteractions(lambdaLogger);
84105
assertEquals(0, config.getNumberOfPlatformThreads());
85106
assertEquals(false, config.isMultiConcurrent());
86107
}

0 commit comments

Comments
 (0)