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
  4. Consider evaluating additional factors such as performance, security, and ease of integration into existing workflows when deciding between Java SDK and JavaScript SDK. For example, integrating industrial automation solutions like a
    paint booth might require unique approaches, while handling tasks such as
    Pulse jet Filter India

    ReplyDelete
  5. Ensure the IAM user has the principle of least privilege applied, granting only the permissions necessary for the specific service to enhance security. For example, securing access to critical resources like
    Pollution Control Equipment in India

    fume scrubbers in India.

    ReplyDelete
  6. If multiple AWS services are required, it's a good practice to modularize the OSGI bundles for better maintainability and to avoid redundant dependencies. For example, modularization can be helpful when managing diverse functionalities like
    Shrink Packing Machines in Delhi
    Shrink Wrapping Machines.

    ReplyDelete
  7. Environment Variables are particularly useful for containerized environments such as Docker, where you can dynamically inject credentials at runtime. This approach is especially valuable in projects requiring services like
    Cartridge Type Bag Filters
    Centrifugal Blowers in India.

    ReplyDelete
  8. If using BundleContext, ensure proper null checks are in place for scenarios where properties might not be set or accessible. This is particularly important in setups managing resources like
    Cartridge Type Bag Filters
    Axial Flow Fans manufacturers.

    ReplyDelete
  9. Consider using AWS Secrets Manager or a secure vault to manage credentials instead of relying on environment-specific solutions like files or system properties. For example, securing sensitive data is critical when working with platforms like
    Invest in Brands
    Industrial Dust Collectors.

    ReplyDelete
  10. Using StaticCredentialsProvider is acceptable for demo purposes, but for production environments, explore using DefaultCredentialsProvider, which supports multiple sources, including EC2/ECS roles and environment variables. This can simplify integration for tasks such as managing
    Pulse jet Filters Cyclone Dust Collectors.

    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

Embed Third party dependency using bnd-maven-plugin