Skip to content

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

Closed
@AnshulRustogi

Description

@AnshulRustogi

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;
	};
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions