aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

ClassNotFoundException in package that works fine on Lambda

Open feinstein opened this issue 5 years ago • 2 comments

I have a Lambda + API Gateway deployment working fine, but when I try to invoke the same ZIP file locally I get a ClassNotFoundException for the same handler string as the one in the Lambda Console.

I am invoking it with:

>sam local start-api --template sam.yaml

My sam.yaml is:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Users API Endpoint
Globals:
  Api:
    EndpointConfiguration: REGIONAL

Resources:
  UsersFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.myproject.users.StreamLambdaHandler::handleRequest
      Runtime: java8
      CodeUri: lambda/build/distributions/lambda-1.0.0-SNAPSHOT
      MemorySize: 320
      Policies: AWSLambdaVPCAccessExecutionRole
      Timeout: 20
      Events:
        GetResource:
          Type: Api
          Properties:
            Path: /users/{proxy+}
            Method: any

Outputs:
  UsersApi:
    Description: URL for application
    Value: !Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/users'
    Export:
      Name: UsersApi
  1. OS: Windows
  2. sam --version: 0.17.0

feinstein avatar Jul 04 '19 04:07 feinstein

was the project built with sam build, before being invoked? if you did can you check .aws-sam/build directory to see if the class files and jars are present?

sriram-mv avatar Jul 11 '19 18:07 sriram-mv

Yes, and it didn't made any difference, BUT if I unzip the deployment package myself, on the same folder (same thing that SAM does), it works.

feinstein avatar Jul 11 '19 18:07 feinstein

Given the age on this issue, I am going to close it. This is from a very old version (we are on 1.72.0 now).

If something is still not working as expected on newer versions, please create a new issue so we can investigate. I fully working example so we can easily repro would be very helpful too.

jfuss avatar Feb 10 '23 03:02 jfuss

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Feb 10 '23 03:02 github-actions[bot]