0

I'm trying to use the Java SDK to programmatically stop an EC2 instance. I'm very new the AWS api, but what I'm trying to do should be very basic:

BasicAWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);

AmazonEC2Client ec2 = new AmazonEC2Client(credentials); //ERROR caused by this line

I've seen several examples of this, for example here. I know the better way to do this is by using IAM roles, but I'm just trying to get something to work first. The line that creates the AmazonEC2 throws this error

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper at com.amazonaws.util.json.Jackson. 

I can't figure out why it's throwing a class definition not found error.

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
user244145
  • 73
  • 1
  • 11
  • can you confirm the access key works or not? download `aws-cli ` (aws command tools) and run directly in shell scriping to confirm you can run the command successfully `aws ec2 describe-instance-status` – BMW Dec 16 '14 at 01:40
  • Ok, I did this and got a good response. I have a question though which maybe I should have included in the original post: if the credentials being wrong were the problem, wouldn't I have gotten a different error, not a class not found error? Or will the errors from the AWS api calls not be descriptive of the problem? – user244145 Dec 16 '14 at 02:04
  • You can test from your end with failed access key. – BMW Dec 16 '14 at 02:05
  • What if the class not found error is thrown before it even checks the access key? – user244145 Dec 16 '14 at 02:07
  • Can you try with this official doc (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-programming-techniques.html) ? – BMW Dec 16 '14 at 02:10
  • Yes, they give an example [here at the bottom](http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html), which is exactly what I'm doing except I'm making an EC2Client instead of an S3Client, so it should work. Also, I tried changing the access keys to the wrong ones and got the same error. – user244145 Dec 16 '14 at 02:15
  • so you get same error with failed access key? then you didn't pass the first step. `access_key_id, secret_access_key` is not same as `ACCESS_KEY, SECRET_KEY` , can you make sure, you have set the enviornment properly? such as : `echo $AWS_CREDENTIAL_FILE` – BMW Dec 16 '14 at 02:48
  • I'm confused. If I'm getting a class not found error, wouldn't that break the line of code before it even checks if the keys are correct? Also, ACCESS_KEY and SECRET_KEY are hardcoded copied from the text file I used to configure the environmental variables for the command line test, so they should be the same. EDIT: I'm at home now so I can't do anything else for today, but tomorrow I might try using the default credential chain instead of creating the credentials using hardcoded values, although theoretically it shouldn't make a difference. – user244145 Dec 16 '14 at 03:05

1 Answers1

0

I figured out the issue. Apparently the AWS library requires three more dependencies in fasterxml.jackson.core. Because I was using Ivy to configure these, I had to add these manually

user244145
  • 73
  • 1
  • 11