Message Boards

Anyone was able to use awssdk in a Liferay 7 module

Marc-Andre Gauthier, modified 2 Years ago.

Anyone was able to use awssdk in a Liferay 7 module

New Member Posts: 21 Join Date: 7/30/15 Recent Posts

We are trying to use Amazon AWS java sdk (1.x or2.x) in our Liferay 7.4.3.4 ga4 module.

Anyone got this working?

Would be appreciated if someone could give us the recipe. 

 

Thanks in advance. 

Marc-Andre Gauthier, modified 2 Years ago.

RE: Anyone was able to use awssdk in a Liferay 7 module

New Member Posts: 21 Join Date: 7/30/15 Recent Posts

Tried adding 

compileInclude 'software.amazon.awssdk:s3:2.17.100'    
compileInclude 'software.amazon.awssdk:sdk-core:2.17.100'

to my build.gradle

Still getting loads of problems deploying module

Unresolved requirement: Import-Package: xyz

like com.google.protobuf etc.

thumbnail
Olaf Kock, modified 2 Years ago.

RE: Anyone was able to use awssdk in a Liferay 7 module

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

The problem with compileInclude is that you'll also need to make sure transitive dependencies are available - those are the missing imports that you see.

As far as I know, you can satisfy those dependencies at runtime, when you deploy them to the OSGi runtime (in case the dependencies are OSGi conforming bundles) or you compileInclude them as well. Or you could avoid functions that need those transitive dependencies: Often such APIs are offering more than you'd immediately need. But that's apparently not the case in this situation.

Marc-Andre Gauthier, modified 2 Years ago.

RE: Anyone was able to use awssdk in a Liferay 7 module (Answer)

New Member Posts: 21 Join Date: 7/30/15 Recent Posts

Thanks Olaf. 

I was hoping you wouldn't say that :)

I was a bit lazy and trying to avoid loading transitive dependencies one by one as AWS sdk has lots of them. 

But since you confirmed that this is the case, I dig a bit more and I found something that is working. It was a bit of a head scratcher but maybe it will help somebody else:

  • I created a empty maven Java project
  • Following this "how to", I exported the AWS-SDK library as an OSGI module using the maven-bundle-plugin from org.apache.felix
    • The important bit is the  <Embed-Transitive>true</Embed-Transitive> in the instructions section of the POM file
    • Ref: https://myaemlearnings.blogspot.com/2021/02/createbuild-and-install-osgi-bundle-of.html
  • Running the "package" maven task creates a jar file in the target directory that contains all the required files, including transitive dependencies
  • I loaded the jar file as a OSGI module in Liferay's runtime
  • I used the following line in build.gradle of the module using the AWS sdk
    • runtime "software.amazon.awssdk:your.artifact.id:x.y.z"

 

Notes:

  • I exported the complete aws library using the following "bundle" dependency so the jar file is quite big (around 300M)
    • <dependencies>
          <dependency>
              <groupId>software.amazon.awssdk</groupId>
              <artifactId>bundle</artifactId>
              <version>2.17.102</version>
          </dependency>
      </dependencies>
  • I think it would be possible to create smaller osgi modules by exporting just parts of the SDK but I didn't try it. 

Thanks again Olaf, your comments are always helpful.