So I am wondering what could be the cause of this error message :
com/amazonaws/services/ec2/AmazonEC2ClientBuilder: java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError: com/amazonaws/services/ec2/AmazonEC2ClientBuilder at com.stopinstance.InstanceControlLambda.(InstanceControlLambda.java:14) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.amazonaws.services.ec2.AmazonEC2ClientBuilder. Current classpath: file:/var/task/
com/amazonaws/services/ec2/AmazonEC2ClientBuilder: java.lang.NoClassDefFoundError
I have checked my dependencies that they are the using the same version, but it seems to me that there is still an issue with the ec2ClientBuilder...
Here is my lambda code: enter image description here
Here is my pom.xml enter image description here
Here is my template.yaml enter image description here
**I would appreciate any help ! **
If you want to use Amazon EC2 and Java, then use the recommended version which is AWS SDK for Java V2, not V1 version. V1 does not reflect best practice.
To use EC2 and Java EC2 API, you use this code to build the client.
The POM file with all the required dependencies can be found in the above link.
If you are not familiar with AWS SDK for Java V2, refer to the DEV Guide.
You can find many EC2 examples here:
Amazon EC2 examples using SDK for Java 2.x