Ask a Question

Can we connect to Dynamo database and Amazon Web Service from Ready API?

SOLVED
dhavalunalket
New Contributor

Can we connect to Dynamo database and Amazon Web Service from Ready API?

 
14 REPLIES 14
nmrao
Community Hero

If you have got a java driver for that db, you should be able to connect. Of course, you can work with any web services. Have you got any specific problem?


Regards,
Rao.

Hi Rao,

      Thank you for the reply. I have some data that is being stored in dynamo database and I am trying to find a way to access these data in ready api. I dont know how to establish a connection and how to make a call to access this data.

 

Thank you,

 

Regards,

Dhaval Unalket

Hi @dhavalunalket

I am also trying for the same. did you find any way to do that? If yes, Can you please share with me.

Hello,

Dynamo db can be accessed via the AWS Java SDK.

 

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Java.html

 

The above link will give java examples that portions can be cut and paste right into groovy scripts.  The SDK (Amazon JAR files) are shipped with ReadyAPI, but I remove them in favor of replacing them with the latest one from Amazon that it updated frequently.  The SDK just has one JAR that is needed (aws-java-sdk-x.xx.xxx.jar) that gets put in the ReadyAPI installation location, lib folder.  The SDK usage for access to other AWS services is really good, so if you are already using it for them, access to Dynamo DB will be easy. 

 

There are JDBC drivers available for DynamoDB, but none of them are free.  Third party companies sell them and none are directly from Amazon.

 

Regards

@TNeuschwanger, Thanks for your response.

 

I have some question regarding your post. maybe it's very silly as I am very new to AWS.

 

1) I am not able to find java example that I can refer. Is something I am missing here?

2) Can't able to find aws-java-sdk-x.xx.xxx.jar for the dynamo DB in SDK. Also, there are so many options (Attached), not able to understand which jar file I need to download.

 SDK.PNG

So basically not getting any idea how can we connect. Is there any blog or some docs from which I can get a bit of knowledge or steps to do this. It will be really helpful for me.

Hello ranujn,

 

answer for: "I am not able to find java example that I can refer. Is something I am missing here?"

The link in my previous response was a tutorial for DynamoDB access using the Java SDK.  The lower right of the bottom of the page contains a Previous|Next link.  The very first press of the 'Next >>' from the link I sent leads to many java examples on subsiquent pages.

 

answer for: "Can't able to find aws-java-sdk-x.xx.xxx.jar for the dynamo DB in SDK. Also, there are so many options (Attached), not able to understand which jar file I need to download."

This link sends you to "AWS SDK for Java" page.  https://aws.amazon.com/sdk-for-java/  The downloads button is to the right on the page.  The current file as of 10-14-2018 is "aws-java-sdk-1.11.428.zip".  When it is unzipped to where ever you choose, you can review the samples contained in extract.  Some of which are stricktly DynamoDB.  The '.lib' folder of the extract contains three JAR files of which you only need to copy the "aws-java-sdk-1.11.428.jar" to the ".lib" folder of where you installed SmartBear ReadyAPI-x.x.x.  There will already be one or two aws-javaxxxxx.jar files in the SmartBear ".lib" that I just deleted in favor of the one I got from Amazon directly.  The dowloaded JAR contains all of the packages needed to use the JDK (including DyanamoDB).

 

 

Thanks, @TNeuschwanger, Its really help me. 

 

One more thing if you can help me here. I am trying to read the data from Dynamo DB so I followed below steps

1). I set both AWS keys in the groovy script and copy below code into Ready API Groovy script and change data related to table

package com.amazonaws.codesamples.gsg; import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec; public class MoviesItemOps02 { public static void main(String[] args) throws Exception { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")) .build(); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); int year = 2015; String title = "The Big New Movie"; GetItemSpec spec = new GetItemSpec().withPrimaryKey("year", year, "title", title); try { System.out.println("Attempting to read the item..."); Item outcome = table.getItem(spec); System.out.println("GetItem succeeded: " + outcome); } catch (Exception e) { System.err.println("Unable to read item: " + year + " " + title); System.err.println(e.getMessage()); } } }

2. when I try to run it, its thowing error for the class I am importing.

 

Could you please help me here. I really appreciate your help. 🙂 

Hello,

 

After completing the pre-requisites, I dropped each code sample from the above tutorial into its own groovy script test step in a sample test case.  I did not encounter any errors during any run of a test step.  It would be very helpful if you indicate what the error was for the class you imported so I might have an idea of how to help since I did not have any class error while trying to reproduce the content of the tutorial. 🙂

Hi @TNeuschwanger

 

The error I am getting

 

at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Script2.groovy: 4: unable to resolve class com.amazonaws.services.dynamodbv2.AmazonDynamoDB
@ line 4, column 1.
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class com.amazonaws.services.dynamodbv2.AmazonDynamoDB
@ line 4, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:149)

cancel
Showing results for 
Search instead for 
Did you mean: