Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

How to manage environment-specific configurations?

Avatar

Level 2

What is the recommended way to manage environment-specific configurations (like API endpoints or feature flags) in AEM as a Cloud Service?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @AryaBa1,

Managing environment-specific configurations should be done using Context-Aware Configuration (CAC) in combination with runmode-specific OSGi configs. Here's a breakdown of the recommended approach:

1. Use Context-Aware Configuration (CAC)

  • CAC allows you to store config values in the content structure (e.g., /conf/my-site) and access them dynamically based on the page context.

  • Example: Store a config.json under /conf/my-site/settings/cloudconfigs/my-api-config.

{
  "apiUrl": "https://dev.api.example.com",
  "featureFlag": true
}
  • Access in Sling Models using @ValueMapValue or via ConfigurationBuilder.

2. Use Runmode-Specific OSGi Configurations

  • Define environment-specific values in /apps/myproject/osgiconfig/config.<runmode>....cfg.json.

  • For example:

/apps/myproject/osgiconfig/config.dev/com.myproject.core.services.MyApiConfig.cfg.json
{
  "api.endpoint": "https://dev.api.example.com"
}
  • The correct config is automatically picked based on the Cloud Manager environment's runmode (dev, stage, prod).

3. Avoid Hardcoding or Environment Detection in Code

  • Never use if(runmode == "dev") logic in code.

  • Instead, inject configuration using OSGi or CAC, and keep code environment-agnostic.

4. Use Adobe Cloud Manager’s Pipeline Variables (if needed)

  • For non-code configuration like secrets or toggles, use Adobe Cloud Manager pipeline variables.

  • Inject them via OSGi or environment variable bridge patterns.

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @AryaBa1,

Managing environment-specific configurations should be done using Context-Aware Configuration (CAC) in combination with runmode-specific OSGi configs. Here's a breakdown of the recommended approach:

1. Use Context-Aware Configuration (CAC)

  • CAC allows you to store config values in the content structure (e.g., /conf/my-site) and access them dynamically based on the page context.

  • Example: Store a config.json under /conf/my-site/settings/cloudconfigs/my-api-config.

{
  "apiUrl": "https://dev.api.example.com",
  "featureFlag": true
}
  • Access in Sling Models using @ValueMapValue or via ConfigurationBuilder.

2. Use Runmode-Specific OSGi Configurations

  • Define environment-specific values in /apps/myproject/osgiconfig/config.<runmode>....cfg.json.

  • For example:

/apps/myproject/osgiconfig/config.dev/com.myproject.core.services.MyApiConfig.cfg.json
{
  "api.endpoint": "https://dev.api.example.com"
}
  • The correct config is automatically picked based on the Cloud Manager environment's runmode (dev, stage, prod).

3. Avoid Hardcoding or Environment Detection in Code

  • Never use if(runmode == "dev") logic in code.

  • Instead, inject configuration using OSGi or CAC, and keep code environment-agnostic.

4. Use Adobe Cloud Manager’s Pipeline Variables (if needed)

  • For non-code configuration like secrets or toggles, use Adobe Cloud Manager pipeline variables.

  • Inject them via OSGi or environment variable bridge patterns.

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


Avatar

Level 5

Hi @AryaBa1 ,

In AEMaaCS, the recommended approach for managing environment-specific configurations - like API endpoints, feature flags, and authentication keys—is to use Adobe's structured configuration methods. These include Context-Aware Configurations (CAConfig), OSGi runmode-specific configurations, and secure secrets management.

1. Context-Aware Configuration (CAConfig)

  • Use the /conf folder to store values like API endpoints and feature flags.

  • Supports inheritance and environment-specific overrides (e.g., /conf/mysite/settings/dev).

  • Access via Sling Models using the ConfigurationBuilder API.

Best for:- Frontend configuration, feature toggles, and dynamic values.

2. Runmode-Specific OSGi Configurations

  • Define OSGi settings directly in the codebase with environment-specific folders:

  • These are deployed with the application code, ensuring consistency across environments.

      ui.config/src/.../config.dev/com.example.MyServiceImpl.cfg.json
      ui.config/src/.../config.prod/com.example.MyServiceImpl.cfg.json

 

Best for: Backend settings like service URLs, timeouts, and integration parameters.

 

3. Secure Secrets Management

  • Do not store secrets (like API keys) in OSGi configs or CAConfig.

  • Instead, use Adobe I/O Runtime Secrets or external vaults (e.g., HashiCorp Vault, Azure Key Vault).

Best for: Secure handling of sensitive credentials and tokens.

 

Try these and let me know if you need more explanation about them.
Thanks.

Avatar

Community Advisor and Adobe Champion

Hi, 

 

Cloud Manager variables are the preferred option for environment-specific configurations. However, if you need to separate configurations based on "path," such as in a multi-tenant setup, then Context-Aware configurations are the appropriate choice

 

You can learn more here: 
https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/usi...
https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/dep... 

 

Hope this helps



Esteban Bustamante