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

Java Handler not found sam 0.3.0 #413

Closed
sashokbg opened this issue May 14, 2018 · 9 comments
Closed

Java Handler not found sam 0.3.0 #413

sashokbg opened this issue May 14, 2018 · 9 comments

Comments

@sashokbg
Copy link

Description:

Hello, since updating to version 0.3 my java lambda cannot find its handler.

Steps to reproduce the issue:

  1. Update to sam local 0.3 via pip
  2. Create a function with java handler
  3. Invoke the function from start-api
sam local start-api --docker-network=sky-net --env-vars ./env_local.json

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  • Ubuntu LTS 17.10
  • Our template:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: Airliquide Jobs Lambdas

Globals:
  Function:
    MemorySize: 192
    Timeout: 120

Parameters:
  targetStage:
    Description: Define stage to which Lambdas/API Gateways should be deployed.
    Type: String
    Default: dev
    AllowedValues:
      - dev
      - integ
      - prod
    ConstraintDescription: Only stages dev, integ and prod are allowed

Resources:
  JobsTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Sub "Job-${targetStage}"
      AttributeDefinitions:
      - AttributeName: id
        AttributeType: S
      KeySchema:
      - AttributeName: id
        KeyType: HASH
      ProvisionedThroughput:
        ReadCapacityUnits: 5
        WriteCapacityUnits: 5

  GetJobList:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "getJobs-${targetStage}"
      Handler: com.mypackage.JobHandler::getList
      CodeUri: ./target/mypackage-1.0-SNAPSHOT.jar
      Policies: AmazonDynamoDBReadOnlyAccess
      Runtime: java8
      Timeout: 100
      Environment:
        Variables:
          TABLE_NAME: !Ref JobsTable
      Events:
        Api:
          Type: Api
          Properties:
            Path: /job
            Method: get

Output of sam --version:

SAM CLI, version 0.3.0

Debug logs:
2018-05-14 14:28:23 Mounting CreateJob at http://127.0.0.1:3000/job [PUT]
2018-05-14 14:28:23 Mounting GetJobList at http://127.0.0.1:3000/job [GET]
2018-05-14 14:28:23 Mounting UpdateJob at http://127.0.0.1:3000/job [POST]
2018-05-14 14:28:23 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2018-05-14 14:28:23 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2018-05-14 14:28:30 Invoking com.mypackage.JobHandler::getList (java8)
2018-05-14 14:28:30 Found credentials in shared credentials file: ~/.aws/credentials
2018-05-14 14:28:30 Decompressing /home/alexander/projects/mypackage/target/mypackage-1.0-SNAPSHOT.jar

Fetching lambci/lambda:java8 Docker container image......
2018-05-14 14:28:33 Mounting /tmp/tmpdCCYam as /var/task:ro inside runtime container
START RequestId: 04199ee0-884e-4f31-a7b2-bc4ec7dd8c13 Version: $LATEST
java.lang.ClassNotFoundException: com.mypackage.handlers.JobHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)

END RequestId: 04199ee0-884e-4f31-a7b2-bc4ec7dd8c13
REPORT RequestId: 04199ee0-884e-4f31-a7b2-bc4ec7dd8c13 Duration: 3.80 ms Billed Duration: 100 ms Memory Size: 192 MB Max Memory Used: 4 MB
2018-05-14 14:28:34 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received:
2018-05-14 14:28:34 127.0.0.1 - - [14/May/2018 14:28:34] "GET /job HTTP/1.1" 502 -

@hubbins
Copy link

hubbins commented May 16, 2018

Appears to have the same issue with dotnetcore2.0 runtime. However, 0.3.0 is the first version of SAM that I have used, so I don't know if this is a new problem. I'm just trying to get something working.

2018-05-16 14:54:00 Decompressing C:\Users\Sean\Documents\src\AwsSamNetCore\AwsSamNetCore\bin\Release\netcoreapp2.0\publish\publish.zip

Fetching lambci/lambda:dotnetcore2.0 Docker container image......
2018-05-16 14:54:07 Mounting c:\users\sean\appdata\local\temp\tmprxqjoo as /var/task:ro inside runtime container

Unhandled Exception: AWSLambda.Internal.Bootstrap.LambdaValidationException: Unable to load type 'AwsSamNetCore.LambdaEntryPoint' from assembly 'AwsSamNetCore'.

@artman186
Copy link

I am experiencing an identical problem. I've been running SAM 0.2.11 for about a month, installed via NPM and haven't had any issues. I just switched to SAM 0.3.0 this morning and I now have an identical issue as the OP, SAM is throwing a ClassNotFoundException for my handlers, even though I've manually verified that they exist within the zip file it claims to be opening. I will switch back to 0.2.11 for now as not being able to work locally is a bit of a blocker.

@jfuss
Copy link
Contributor

jfuss commented May 22, 2018

Smells of the same issue reported here #389. There is a work around listed there, namely don't zip and just point the CodeUri to the jar. Without further investigation, I can't say if they are the same or not but worth a shot.

@artman186
Copy link

Interestingly enough, after reverting back to 0.2.11 I'm having the exact same problem. I removed all of the docker instances and images and tried from scratch and I'm still getting the ClassNotFoundException for my handler. I'm a little baffled at this point.

@artman186
Copy link

@jfuss I think you are correct. After pointing my template directly at the output folder instead of the zip file it started working, both with versions 0.2.11 and 0.3.

@sanathkr
Copy link
Contributor

We need integration tests with Java Lambda Function code to make sure this scenario is covered and worked.

@yoelb
Copy link

yoelb commented May 27, 2018

Same issue, when unzipping its work. when specifing jar or zip it doesnt work.
Sam version : 0.3

@fvasco
Copy link

fvasco commented May 28, 2018

Same issue using Java sample (commit f1c4c49, now documented in README but removed)

@sanathkr
Copy link
Contributor

sanathkr commented Jun 6, 2018

Added an integration test in #464. Closing this one as dupe of #389. Follow that issue for updates.

@sanathkr sanathkr closed this as completed Jun 6, 2018
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

7 participants