Expand my Community achievements bar.

Feasible Way to Share Token Across All Publishers in AEM as a Cloud Service?

Avatar

Level 2

Hi everyone,

In our AEM as a Cloud Service project, we are generating an **access token inside an OSGi service class**. Every time we call the method in this service, it generates a **new token**.

The requirement is:

* The token should be **generated only once every 24 hours**
* The same token should be **reused across all publish instances** within that 24-hour window

Since AEM as a Cloud Service is **stateless** and each publish instance runs independently, using in-memory storage or static variables doesn’t help — the token is regenerated on every call from different instances.

Is there any feasible or recommended way to store and share this token across all publish instances in AEM as a Cloud Service?

Looking for a lightweight, cloud-compatible solution. Appreciate any guidance!

Thanks!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

8 Replies

Avatar

Level 2

Hi @sai_charanAr 
Store the token in the shared JCR repository (e.g., under /var/myproject/token), which is accessible by all instances.

Avatar

Level 2

Hi @Karishma_begumSh ,is it recommended update the repository in publisher even if we save (var/myproject/token ) how we can sync with multiple publisher ?

Avatar

Level 2

No, it is not recommended to write to the JCR repository from publish instances, even under /var, especially in AEM as a Cloud Service because as it is stateless it allows only to read.
instead use external token store or use shared token generator service

Avatar

Community Advisor

@sai_charanAr I would recommend you to develop this api outside of aem like in Adobe io Runtime or any other middleware api where access token is generated and calls external service or any other operation post that.. and you call adobe io runtime/middle layer api from your publisher everytime

Avatar

Community Advisor

Hi @sai_charanAr ,

We have to store outside AEM like Redis Cache of Azure/ AWS.

Our design was based on  2 level of cache mechanism to avoid call to external API each time.

  • Put token ( data ) in Gauva cache(in memory) and Azure redis cache
  • While checking(accessing), first check in OSGI / Gauva Cache in the AEM itself
  • If it is not present in AEM check in the external(Azure Redis cache)

This way were able to achieve the desired functionality in efficient manner.

 

Thanks

Avatar

Community Advisor

Hi @sai_charanAr ,

 

External Token Store with Local Cache

Summary

1 . Use an external shared store (e.g., Redis, AWS SSM, Azure Key Vault, or S3/Blob).

2. Each AEM publish instance:

  - First checks local memory (e.g., Guava cache).

  - If not found, fetches from the external store.

  - If expired or not present in store, one instance regenerates the token and stores it.

3. Use OSGi Scheduler or lazy-load logic to regenerate every 24h.

Regards,
Amit

Avatar

Community Advisor

@sai_charanAr Store it in jcr node and maintain sticky session to read value from specific publishers.

Avatar

Community Advisor

Hi @sai_charanAr ,

 

Is there any update on this problem? If so, please let the community know.

 

 

Thanks,

Aditya Chabuku