Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWSLambdaUtils throw NullPointerException when function return type is com.amazonaws.services.lambda.runtime.events #1210

Closed
AnshulRustogi opened this issue Nov 28, 2024 · 4 comments

Comments

@AnshulRustogi
Copy link

AnshulRustogi commented Nov 28, 2024

AWSLambdaUtils throw NullPointerException when function return type is com.amazonaws.services.lambda.runtime.events

Any function on AWS returning an object of S3Event/ScheduledEvent (from package: com.amazonaws.services.lambda.runtime.events) is giving null pointer exception
java.lang.NullPointerException: Cannot invoke "org.springframework.messaging.Message.getPayload()" because "msg" is null

	at org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.extractPayload(AWSLambdaUtils.java:152)
	at org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateOutput(AWSLambdaUtils.java:216)
	at org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateOutputFromObject(AWSLambdaUtils.java:208)
	at org.springframework.cloud.function.adapter.aws.FunctionInvoker.handleRequest(FunctionInvoker.java:95)

Test Case for recreate the issue

FunctionInvokerTests.class

@Test
public void testS3EventAsOutput() throws Exception {
    System.setProperty("MAIN_CLASS", S3Configuration.class.getName());
    System.setProperty("spring.cloud.function.definition", "outputS3Event");
    FunctionInvoker invoker = new FunctionInvoker();

    InputStream targetStream = new ByteArrayInputStream(this.s3Event.getBytes());
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    invoker.handleRequest(targetStream, output, null);
    assertNotNull(output.toByteArray());
}

Below function can be added in S3Configuration subclass in test class

@Bean
public Function<S3Event, S3Event> outputS3Event() {
	return v -> {
		System.out.println("Received: " + v);
		return v;
	};
}
@AnshulRustogi AnshulRustogi changed the title AWSLambdaUtils throw NullPointerException when AWSLambdaUtils throw NullPointerException when objects from com.amazonaws.services.lambda.runtime.events is returned from Function Nov 28, 2024
@AnshulRustogi AnshulRustogi changed the title AWSLambdaUtils throw NullPointerException when objects from com.amazonaws.services.lambda.runtime.events is returned from Function AWSLambdaUtils throw NullPointerException when function return type is com.amazonaws.services.lambda.runtime.events Nov 28, 2024
@AnshulRustogi
Copy link
Author

Sample Code to recreate issue in AWS: https://github.com/AnshulRustogi/SpringCloudFunctionAdapterAWS

@AnshulRustogi
Copy link
Author

Hi, is there any update on the issue?

@olegz
Copy link
Contributor

olegz commented Dec 17, 2024

Looking

@AnshulRustogi
Copy link
Author

@olegz I believe the current added solution works for S3Event, would it be possible to have a more generic solution to work for all AWS events (eg: lambda events) to not give nullPointerException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants