Grails with DynamoDB

421 views
Skip to first unread message

Brandon Wagner

unread,
Oct 10, 2014, 10:31:26 PM10/10/14
to grails-de...@googlegroups.com
I was wondering if anyone has had experience with using DynamoDB with Grails (2.4.3). I know there is a DynamoDB plugin but hasn't been updated in over two years. I was hoping to get some advise with integrating DynamoDB as the datastore for my application. Right now I'm using MongoDB, but I wanted to use DynamoDB for its ease of use and scale on the Amazon platform.
Message has been deleted

Benoit Hediard

unread,
Oct 11, 2014, 3:45:56 AM10/11/14
to grails-de...@googlegroups.com
We are using DynamoDB in production with Grails and it's great!
Indeed, DynamoDB GORM Plugin is not maintained (and probably use a deprecated API).

So we are using the Mapper provided by the AWS Java SDK: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaSDKHighLevel.html
We create our 'domain' classes in Java with the corresponding mapper annotations.
Then we use a Grails service to wrap mapper calls with more "groovy" methods: createTable(), query(), get(), save(), increment(), etc.

If you are interested, I could add this service and some documentation to the AWS SDK Grails Plugin.
Let me know.

Brandon Wagner

unread,
Oct 12, 2014, 3:47:08 PM10/12/14
to grails-de...@googlegroups.com
That is interesting. However, I'm looking for a more flexible solution. I'd like to be able to use the GORM API and switch with little effort. We're a small startup and don't want to spend a lot of time rewriting code to try something out.

It looks like our best option (with keeping to GORM), is to stay with MongoDB and provision our own MongoDB servers on EC2 instances with a custom backup and scaling implementation.

Eric Wu

unread,
Feb 2, 2015, 10:26:41 PM2/2/15
to grails-de...@googlegroups.com
Hi Benoit

We are looking into Grails & DynamoDB as well. Can you please shed some light on the groovy mapper wrappers? 

Cheers
Eric

Benoit Hediard

unread,
Feb 3, 2015, 4:19:29 AM2/3/15
to grails-de...@googlegroups.com
Hi Eric,

Here is our DynamoDBService abstract class:

How to use it:
1. create your Java-based domain class with DynamoDB java mapper (see SampleUser.java https://gist.github.com/benorama/b8ebe911da703b6ba96d#file-sampleuser-java)
2. create a Grails service that extends DynamoDBService and initialize it with your Java-based class (see SampleUserDBService.groovy https://gist.github.com/benorama/b8ebe911da703b6ba96d#file-sampleuserdbservice-groovy)

You can then use this service to interact with DynamoDB.
Example:
// Get user
SampleUser user = sampleUserDBService.get(1, 1) as SampleUser
if (!user) {
    user = new SampleUser(
             hashKey: 1,
             rangeKey: 1,
             name: 'foo'
    )
}

// Save user
sampleUserDBService.save(user)

// Update user name
sampleUserDBService.updateItemAttribute(1, 1, 'name', 'bar')

// List users by hash key
sampleUserDBService.query(1)

// Delete user
sampleUserDBService.delete(user) // or sampleUserDBService.delete(1, 1)

Let me know how it goes!

Benoit

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/0REDOVI5Jg8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/f8430f16-d30e-4107-a02e-8a77ebc3440c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Stadler

unread,
May 4, 2018, 8:13:57 PM5/4/18
to Grails Dev Discuss
Hi Benoit:

Today I ran across the AWS SDK plugins you've provided, and specifically have been trying to get the DynamoDB plugin to work, but having quite a few problems getting it set up.

Here are the specs:

grails -v
| Grails Version: 3.3.2
| Groovy Version: 2.4.13
| JVM Version: 1.8.0_25

I have altered build.gradle with the following 2 lines:
in repositories:   maven { url 'http://dl.bintray.com/agorapulse/libs' }
in dependencies:  compile 'org.grails.plugins:aws-sdk-dynamodb:2.1.5'

I am able to compile up to this step:

However when I try the service definition step:

I am getting this:

/Users/dstadler/Documents/code/boxfuse/getstarted-grails/grails-app/services/getstarted/grails/FooItemDBService.groovy: 4: unable to resolve class grails.plugins.awssdk.dynamodb.AbstractDBService
 @ line 4, column 1.
   import grails.plugins.awssdk.dynamodb.AbstractDBService
   ^

This is failing when I try to compile from the grails command line, and as a side note I have not been able to successfully get dependencies working with Intellij either.

Any assistance appreciated: I would really like to try converting a Grails3 app to run using all of the AWS services that your plugin supports.

- dan
Reply all
Reply to author
Forward
0 new messages