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:
- AWS IAM user with Programmatic access type and with permissions to desired service set via Groups in IAM
- Access Key and Secret key pertaining to the user as created above.
- Reference : https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html
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:
- We can make use of simple maven project as mentioned in my previous post to build and install OSGI bundle out of desired AWS Java SDK V2 (maven dependency - https://mvnrepository.com/artifact/software.amazon.awssdk)
- Decide on the service and use its respective maven dependency to build and install OSGI bundle out of the same.
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
This post is so interactive and informative.keep updating more information...
ReplyDeleteAWS Training In Mumbai
AWS Training In Ahmedabad
AWS Training In Kochi
AWS Training In Trivandrum
AWS Training In Kolkata
ReplyDeleteThanks 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
Thanks for sharing this informative article on AWS Service in AEM. If you want to java development company for your project. Please visit us.
ReplyDeleteOur 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.
ReplyDeleteConsider 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
ReplyDeletepaint booth might require unique approaches, while handling tasks such as
Pulse jet Filter India
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
ReplyDeletePollution Control Equipment in India
fume scrubbers in India.
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
ReplyDeleteShrink Packing Machines in Delhi
Shrink Wrapping Machines.
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
ReplyDeleteCartridge Type Bag Filters
Centrifugal Blowers in India.
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
ReplyDeleteCartridge Type Bag Filters
Axial Flow Fans manufacturers.
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
ReplyDeleteInvest in Brands
Industrial Dust Collectors.
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
ReplyDeletePulse jet Filters Cyclone Dust Collectors.