serverless / serverless/serverless

AWS Lambda Handler Severless Invoke local : Class Not found

Open
#6,277 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug cat/local-dev
Dominant language
JavaScript
Stars
46.9k
Forks
5.7k
Avg merge
10h 7m
Merged PRs (30d)
57

Description

Hey Guys,

So I've been struggling on this since two weeks now ....

So i'm trying to make my handler encrypt some file and return me a string, the encrypt function just return a base64 string the one i want:

`public class Handler implements RequestHandler<Map<String, String>, String>{

@Override
public String handleRequest(Map<String, String> input, Context context) {
	context.getLogger().log("Input: " + input);
	
	Response rep = new Response(input);
	
	String output = "File: " ;
	String temp = rep.getType();
	
	if(temp.equals("pdf")) {
		
		output += Encrypt.encryptPDF(rep.getFile(), rep.getUserPwd(), rep.getOwnerPwd());
	}
	if(temp.equals("xlsx")) {
		output += Encrypt.encryptXLSX(rep.getFile(), rep.getPassword(), rep.getFilename());
	}
	if(temp.equals("zip")) {
		output += "OK";
	}
	
	return output;
}

}`

Here is my description of the handler on serverless.yml:

functions: encrypt: handler: com.spinifexit.file.security.aws.Handler::handleRequest

And My issue when i try to invoke it on local:

`sls invoke local --function encrypt

Serverless: In order to get human-readable output, please implement "toString()" method of your "ApiGatewayResponse" object.

java.lang.ClassNotFoundException: com.spinifexit.file.security.aws.Handler

    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.serverless.InvokeBridge.getInstance(InvokeBridge.java:69)
    at com.serverless.InvokeBridge.<init>(InvokeBridge.java:37)
    at com.serverless.InvokeBridge.main(InvokeBridge.java:150)`

For now i'm not passing data yet but i already tried with some still the same.

My Environment:
-AWS Java SDK lambda v1.11.546
-AWS lambda java core v1.2.0
-JDK v1.8.0_211

Thanks :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with serverless.yml and reproduce the failure using sls invoke local --function encrypt, then trace how the Java handler class is packaged and loaded for local invocation. Done means the configured com.spinifexit.file.security.aws.Handler class is found and the encrypt function can be invoked locally.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, java
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.