Open anudina opened 4 years ago
How did you build and package the application?
@sapessi and @anudina
I had the same issue.
I did a "gradle clean build" on aws-serverless-java-container-master\samples\springboot2\pet-store
And then referred "build\libs\pet-store.jar" in the CodeUri attribute of the template.yml
`AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Example Pet Store API written with SpringBoot with the aws-serverless-java-container library
Globals: Api:
EndpointConfiguration: REGIONAL
Resources: PetStoreFunction: Type: AWS::Serverless::Function Properties: Handler: com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler::handleRequest Runtime: java8 CodeUri: build\libs\pet-store.jar MemorySize: 1512 Policies: AWSLambdaBasicExecutionRole Timeout: 60 Events: HttpApiEvent: Type: HttpApi Properties: TimeoutInMillis: 20000 PayloadFormatVersion: '1.0'
Outputs: SpringBootPetStoreApi: Description: URL for application Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/pets' Export: Name: SpringBootPetStoreApi `
Once I deployed, I got 502 Bad Gateway while testing the API endpoint.
When I looked into CloudWatch logs, I found
Class not found: com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler: java.lang.ClassNotFoundException java.lang.ClassNotFoundException: com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler at java.net.URLClassLoader.findClass(URLClassLoader.java:382) 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)
Can you please advise on this.
Spring boot version: 2.2.6.RELEASE Gradle : 6.3
I have the exact same issue when building and deploying the springboot2 sample application. Do you have any updates about this problem ?
I am facing same issue , already spent lot of time looking for solution. Anyone solved this?
I have the same issue updates?
In template.yml file:
CodeUri according to maven or gradle setting.
I use maven and change to "./target/my-service-1.0-SNAPSHOT-lambda-package.zip"
Facing the same. can someone give solution to this issue
Hi, there is no need to modify the CodeUri manually.
Just follow the steps as described in the readme: https://github.com/awslabs/aws-serverless-java-container/blob/master/samples/springboot2/pet-store/README.md
I just tried it with master and dev branch and it was working without any issues.
Thank you for your answer. Can you provide me any link where Cloudformation is not used. Is there any way where in I can do through terraform or UI console
@alpasarupria you can also do it without SAM and CloudFormation. I'm not a Terraform expert but looking at https://github.com/hashicorp/terraform/issues/8344 Terraform allows to zip AWS Lambda functions on the fly. The documentation is here: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function
The UI also supports upload from ZIP https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html#gettingstarted-package-zip but I would recommend to use some sort of tool support.
in the root of the project, you need to run:
sam build -u
before you can run:
sam local start-api
and test in browser:
127.0.0.1:3000/pets
Leaving a comment for future me. This turned out to be a selinux issue https://github.com/aws/aws-sam-cli/issues/2360
when I invoke Lambda for Petstore using postman or using test feature in lambda console in
URL invoked: https://hostnameXXXXXXX/lambda/petstore
AWS I get below error "START RequestId: 78c5fb37-4f7e-43e9-a9aa-e4266eb5711b Version: $LATEST Class not found: com.madman.lambda.StreamLambdaHandler: java.lang.ClassNotFoundException java.lang.ClassNotFoundException: com.madman.lambda.StreamLambdaHandler at java.net.URLClassLoader.findClass(URLClassLoader.java:382) 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: 78c5fb37-4f7e-43e9-a9aa-e4266eb5711b"
Expected behavior ; It should work and provide me pets
Actual behavior : throwing error
Steps to reproduce : deploy petstore app for springboot2 in aws lambda and invoke GET operation using ALB trigger or API trigger
Full log output