Skip to content

Commit a1428b9

Browse files
committedOct 2, 2024
bump aws-lambda-java-runtime-interface-client to 2.5.1
1 parent 01bb025 commit a1428b9

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed
 

‎lambda-exec-wrapper.sh

+33-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,37 @@
1919
# com.amazonaws.services.lambda.runtime.api.client.AWSLambda
2020
# com.sigpwned.lambdainternals.App::handleRequest
2121

22+
# Example Java17 CLI a/o Oct 2024:
23+
# /var/lang/bin/java
24+
# -XX:MaxHeapSize=445645k
25+
# -javaagent:/var/runtime/lib/Log4jHotPatch.jar=log4jFixerVerbose=false
26+
# -XX:+UseSerialGC
27+
# -Xshare:on
28+
# -XX:SharedArchiveFile=/var/lang/lib/server/runtime.jsa
29+
# -XX:+TieredCompilation
30+
# -XX:TieredStopAtLevel=1
31+
# --add-opens=java.base/java.io=ALL-UNNAMED
32+
# -Dorg.crac.Core.Compat=com.amazonaws.services.lambda.crac
33+
# -XX:+ErrorFileToStderr
34+
# -Dcom.amazonaws.services.lambda.runtime.api.client.runtimeapi.NativeClient.JNI=/var/runtime/lib/jni/libaws-lambda-jni.linux-x86_64.so
35+
# -classpath
36+
# /var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.5.1-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar
37+
# com.amazonaws.services.lambda.runtime.api.client.AWSLambda
38+
# com.sigpwned.lambdainternals.App::handleRequest
39+
40+
# To check or update the above command line, run the lambdainternals Lambda
41+
# Function in AWS account product-humangraphics-prod (382363607278). That
42+
# implementation comes from the following GitHub repo:
43+
# https://github.com/sigpwned/the-lambda-iceberg-dissecting-the-official-java-runtimes
44+
2245
# Dump our env
2346
env
2447

2548
# Unpack our tmpdump, if we have one
49+
# Remember, /opt/humangraphics is where this custom layer ("humangraphics")
50+
# be unpacked.
2651
pushd /tmp
27-
/var/lang/bin/java -classpath /var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.5.0-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar:/opt/humangraphics io.humangraphics.backend.lambda.TmpDump "s3://$HUMANGRAPHICS_BUCKET/tmpdump/$AWS_LAMBDA_FUNCTION_NAME.zip"
52+
/var/lang/bin/java -classpath /var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.5.1-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar:/opt/humangraphics io.humangraphics.backend.lambda.TmpDump "s3://$HUMANGRAPHICS_BUCKET/tmpdump/$AWS_LAMBDA_FUNCTION_NAME.zip"
2853
popd
2954

3055
# Grab our args
@@ -36,15 +61,14 @@ do
3661
if [ ${ARGS[$i]} = "-classpath" ]
3762
then
3863
# Add /var/task, /opt/humangraphics to the classpath so ServiceLoader works
64+
#
65+
# Reading the original AWSLambda suggests that we should add /opt/java too.
66+
# Consulting CustomerClassLoader indicates we ACTUALLY need to add all JARs
67+
# in /var/task/lib and /opt/java/lib.
68+
#
69+
# Checking the actual lambda container reveals there are no such JARs. So,
70+
# the below will do.
3971
ARGS[$i+1]="${ARGS[$i+1]}:/var/task:/opt/humangraphics"
40-
elif [ ${ARGS[$i]} = "-XX:+TieredCompilation" ]
41-
then
42-
# We actually do NOT want tiered compilation, thank you
43-
ARGS[$i]="-XX:-TieredCompilation"
44-
elif [ ${ARGS[$i]} = "-XX:TieredStopAtLevel=1" ]
45-
then
46-
# We don't want this, so skip it.
47-
continue
4872
elif [ ${ARGS[$i]} = "com.amazonaws.services.lambda.runtime.api.client.AWSLambda" ]
4973
then
5074
# We want our entry point, not theirs, thank you

‎pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@
7373
<dependency>
7474
<groupId>org.apache.commons</groupId>
7575
<artifactId>commons-compress</artifactId>
76-
<version>1.24.0</version>
76+
<version>1.27.1</version>
7777
</dependency>
7878
<!-- These are all provided by the lambda container: -->
7979
<!-- https://docs.aws.amazon.com/lambda/latest/dg/lambda-java.html -->
8080
<dependency>
8181
<groupId>com.amazonaws</groupId>
8282
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
83-
<version>2.5.0</version>
83+
<version>2.5.1</version>
8484
<scope>provided</scope>
8585
</dependency>
8686
<!-- For testing -->

‎src/main/java/io/humangraphics/backend/lambda/thirdparty/com/amazonaws/services/lambda/runtime/api/client/AWSLambda.java

+21-23
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import com.amazonaws.services.lambda.runtime.api.client.logging.LambdaContextLogger;
2828
import com.amazonaws.services.lambda.runtime.api.client.logging.LogSink;
2929
import com.amazonaws.services.lambda.runtime.api.client.logging.StdOutLogSink;
30+
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaError;
3031
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeApiClient;
3132
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeApiClientImpl;
33+
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.RapidErrorType;
3234
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.converters.LambdaErrorConverter;
3335
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.converters.XRayErrorCauseConverter;
3436
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest;
35-
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.LambdaError;
36-
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.XRayErrorCause;
3737
import com.amazonaws.services.lambda.runtime.api.client.util.LambdaOutputStream;
3838
import com.amazonaws.services.lambda.runtime.api.client.util.UnsafeUtil;
3939
import com.amazonaws.services.lambda.runtime.logging.LogFormat;
@@ -54,6 +54,8 @@
5454
*/
5555
public class AWSLambda {
5656

57+
protected static ClassLoader customerClassLoader;
58+
5759
private static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore";
5860

5961
private static final String JAVA_SECURITY_PROPERTIES = "java.security.properties";
@@ -75,8 +77,6 @@ public class AWSLambda {
7577
private static final String AWS_LAMBDA_INITIALIZATION_TYPE =
7678
System.getenv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_INITIALIZATION_TYPE);
7779

78-
protected static ClassLoader customerClassLoader;
79-
8080
private static LambdaRuntimeApiClient runtimeClient;
8181

8282
static {
@@ -218,16 +218,13 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
218218
String taskRoot = System.getProperty("user.dir");
219219
String libRoot = "/opt/java";
220220
// Make system classloader the customer classloader's parent to ensure any aws-lambda-java-core
221-
// classes
222-
// are loaded from the system classloader.
223-
224-
225-
// aboothe 20240620 just use the system class loader. This allows us to load code from the
226-
// ServiceLoader, which we otherwise could not do using the custom class loader.
221+
// classes are loaded from the system classloader.
227222
//
228223
// customerClassLoader =
229224
// new CustomerClassLoader(taskRoot, libRoot, ClassLoader.getSystemClassLoader());
230-
//
225+
226+
// aboothe 20240620 just use the system class loader. This allows us to load code from the
227+
// ServiceLoader, which we otherwise could not do using the custom class loader.
231228
customerClassLoader = ClassLoader.getSystemClassLoader();
232229

233230
Thread.currentThread().setContextClassLoader(customerClassLoader);
@@ -239,7 +236,8 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
239236
} catch (UserFault userFault) {
240237
lambdaLogger.log(userFault.reportableError(),
241238
lambdaLogger.getLogFormat() == LogFormat.JSON ? LogLevel.ERROR : LogLevel.UNDEFINED);
242-
LambdaError error = LambdaErrorConverter.fromUserFault(userFault);
239+
LambdaError error = new LambdaError(LambdaErrorConverter.fromUserFault(userFault),
240+
RapidErrorType.BadFunctionCode);
243241
runtimeClient.reportInitError(error);
244242
System.exit(1);
245243
return;
@@ -261,23 +259,23 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
261259
try {
262260
payload = requestHandler.call(request);
263261
runtimeClient.reportInvocationSuccess(request.getId(), payload.toByteArray());
264-
boolean ignored = Thread.interrupted(); // clear interrupted flag in case if it was set by
265-
// user's code
262+
// clear interrupted flag in case if it was set by user's code
263+
boolean ignored = Thread.interrupted();
266264
} catch (UserFault f) {
267265
shouldExit = f.fatal;
268266
userFault = f;
269267
UserFault.filterStackTrace(f);
270-
271-
LambdaError error = LambdaErrorConverter.fromUserFault(f);
268+
LambdaError error =
269+
new LambdaError(LambdaErrorConverter.fromUserFault(f), RapidErrorType.BadFunctionCode);
272270
runtimeClient.reportInvocationError(request.getId(), error);
273271
} catch (Throwable t) {
274272
shouldExit = t instanceof VirtualMachineError || t instanceof IOError;
275273
UserFault.filterStackTrace(t);
276274
userFault = UserFault.makeUserFault(t);
277275

278-
LambdaError error = LambdaErrorConverter.fromThrowable(t);
279-
XRayErrorCause xRayErrorCause = XRayErrorCauseConverter.fromThrowable(t);
280-
runtimeClient.reportInvocationError(request.getId(), error, xRayErrorCause);
276+
LambdaError error = new LambdaError(LambdaErrorConverter.fromThrowable(t),
277+
XRayErrorCauseConverter.fromThrowable(t), RapidErrorType.UserException);
278+
runtimeClient.reportInvocationError(request.getId(), error);
281279
} finally {
282280
if (userFault != null) {
283281
lambdaLogger.log(userFault.reportableError(),
@@ -293,16 +291,16 @@ static void onInitComplete(final LambdaContextLogger lambdaLogger) throws IOExce
293291
runtimeClient.restoreNext();
294292
} catch (Exception e1) {
295293
logExceptionCloudWatch(lambdaLogger, e1);
296-
LambdaError error = LambdaErrorConverter.fromThrowable(e1);
297-
runtimeClient.reportInitError(error);
294+
runtimeClient.reportInitError(new LambdaError(LambdaErrorConverter.fromThrowable(e1),
295+
RapidErrorType.BeforeCheckpointError));
298296
System.exit(64);
299297
}
300298
try {
301299
Core.getGlobalContext().afterRestore(null);
302300
} catch (Exception restoreExc) {
303301
logExceptionCloudWatch(lambdaLogger, restoreExc);
304-
LambdaError error = LambdaErrorConverter.fromThrowable(restoreExc);
305-
runtimeClient.reportRestoreError(error);
302+
runtimeClient.reportRestoreError(new LambdaError(
303+
LambdaErrorConverter.fromThrowable(restoreExc), RapidErrorType.AfterRestoreError));
306304
System.exit(64);
307305
}
308306
}

0 commit comments

Comments
 (0)