Skip to content

Error invoking lambda #2869

@JChrist

Description

@JChrist

Describe the bug

After updating from version 2.17.81 to 2.17.85, we get a NoClassDefFoundError when attempting to invoke a lambda method.

Expected behavior

The lambda invocation should proceed without errors initializing implementation classes

Current behavior

Currently, when attempting to invoke a lambda function, it fails with the following stacktrace:

java.lang.NoClassDefFoundError: Could not initialize class software.amazon.awssdk.services.lambda.transform.InvokeRequestMarshaller
        at software.amazon.awssdk.services.lambda.DefaultLambdaClient.invoke(DefaultLambdaClient.java:2356)
        at [...reducted, our own point of invocation]

Steps to Reproduce

The code to invoke the lambda function is the same for both the working version of the sdk 2.17.81 and the non-working 2.17.85 (simplified to the minimum):

try {
  var awsLambda = LambdaClient.builder()
                    .credentialsProvider(InstanceProfileCredentialsProvider.create())
                    .region(Region.EU_WEST_1)
                    .build();
  final var myPayload = "{\"my\": \"payload\"}";
  var invokeRequest = InvokeRequest.builder().functionName("my-function-name")
                    .payload(SdkBytes.fromUtf8String(myPayload)).build();
  var invokeResponse = awsLambda.invoke(invokeRequest);
  String ans = invokeResponse.payload().asUtf8String();
  logger.info("after invoking lambda: {}", ans);
} catch (Throwable e) {
  logger.warn("error invoking lambda", e);
}

Please note that catching an Exception is not enough, since the actual throwable is a NoClassDefFoundError.

Possible Solution

There seems to be an invalid call to a missing method inside the InvokeRequestMarshaller.
Specifically, in version 2.17.81, the SDK_OPERATION_BINDING initializer was:

private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder()
            .requestUri("/2015-03-31/functions/{FunctionName}/invocations").httpMethod(SdkHttpMethod.POST)
            .hasExplicitPayloadMember(true).hasPayloadMembers(true).build();

while in 2.17.82+ it became:

private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder()
            .requestUri("/2015-03-31/functions/{FunctionName}/invocations").httpMethod(SdkHttpMethod.POST)
            .hasExplicitPayloadMember(true).hasImplicitPayloadMembers(false).hasPayloadMembers(true).build();

The error possibly is due to the hasImplicitPayloadMembers call, which does not seem to be actually included in the OperationInfo.Builder class

Context

I am trying to invoke a lambda method from Java, with our custom payload as JSON String.

AWS Java SDK version used

2.17.85

JDK version used

openjdk 17.0.1 2021-10-19 OpenJDK Runtime Environment (build 17.0.1+12-39) OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)

Operating System and version

Docker with base: FROM openjdk:17-jdk

Metadata

Metadata

Assignees

No one assigned

    Labels

    guidanceQuestion that needs advice or information.response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 10 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions