AWS Service in AEM

 This post details the steps to make use of AWS service in web application developed using AEM.

For incorporating any third party services/APIs in AEM, we have two direct possible routes - Via Java SDK(as available in Maven Central) and via Javascript SDK. Choice between the two depends on the availability, functional requirement and existing project set up. 

With respect to AWS services, we have both SDK available and in this post, I am using AWS JAVA SDK V2. 

Note : The intention of this post is to demonstrate the ways to make use of AWS service in AEM projects and not to illustrate about the AWS service itself. 

Prerequisites:

Approach:

  • Include SDK in code base.
  • Set up the acquired Security credentials(Access key and Secret key)
  • Code the desired functionality

Include SDK in code base:

With this step, AWS service of interest will be available in our instance in the form of OSGI bundle. 

Set up the acquired Security credentials:

  • We need to set the credentials as default credentials for accessing the APIs from within our application for which we can use one of the below methods
    • Using credentials file
    • Environment Variables
    • Java System properties
  • First two methods can be followed as is in the AWS doc while the third method - Java System properties slightly differs in the context of AEM. 
  • In AEM, we can set up Java System properties while starting an instance by executing Quickstart.jar or in start.bat script in CQ_JVM_OPTS as highlighted below
  • The properties can then be accessed in the code using BundleContext.getProperty("aws.accessKeyId") and BundleContext.getProperty("aws.secretKey")
  • Note : We should never use the credentials directly/hardcode in the code or it shouldn't be part of SCM. 
With this step, we are done with setting up our AWS IAM account credentials as default credentials for accessing AWS APIs from within our application. 

Code the desired functionality:

  • Very first step in making use of any service in coding standpoint is to instantiate the desired service client as highlighted in red in below screenshot
    • While instantiating the client, we have options to specify the AWS region and credentials provider.
    • Details about the credentials provider is documented in AWS doc
    • Note : For the demo use case, have used Java System properties as mentioned in previous section and the way we retrieve the System properties in the context of AEM is different, the applicable credentialsProvider is  StaticCredentialsProvider.
    • If environment variable/ credentials file is used to set Access Key and Secret key, then we need not specify the credentialsProvider while instantiating the client. It will be handled as part of the SDK (as explained in above AWS doc)
  • Make use of available methods/functions available as part of the service client as highlighted in green in below screenshot


  • Reference : Code samples for Java SDK V2 for each of the service is available in the AWS doc

Demo:

Use case : Send notification to AWS SNS topic about the workflow payload (simple use case for better clarity and to show case the ease of using the API in our AEM project code base)
Code is available in my GitHub repo 
Files Modified:
  • pom.xml (SNS dependency)
  • core/pom.xml (SNS dependency)
  • PushNotificationToSNSProcess.java

Comments


  1. Thanks for taking your valuable time to share this awesome article with us. This is really informative. Looking forward to learn more from you.
    Cloud Computing Training in Chennai
    Cloud Computing Online Training
    Cloud Computing Course in Coimbatore

    ReplyDelete
  2. Thanks for sharing this informative article on AWS Service in AEM. If you want to java development company for your project. Please visit us.

    ReplyDelete
  3. Our team of experienced instructors comprises industry veterans and certified AWS Course in Noida professionals who are passionate about teaching and dedicated to your success. With their guidance and mentorship, you'll receive personalized attention and support throughout your learning journey.

    ReplyDelete

Post a Comment

Popular posts from this blog

Embedding Third party dependency/OSGi bundle in AEM application hosted in AEMasCS

OSGI Factory Configuration implementation

Creation of Template Types for Editable templates