How to manage environment-specific configurations? | Community
Skip to main content
Level 2
May 9, 2025
Solved

How to manage environment-specific configurations?

  • May 9, 2025
  • 3 replies
  • 1020 views

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

Best answer by SantoshSai

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!

3 replies

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
May 9, 2025

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
Level 4
May 9, 2025

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.

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 9, 2025

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/using-cloud-manager/environment-variables#overview
https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/deploying/configuring-osgi#when-to-use-non-secret-environment-specific-configuration-values 

 

Hope this helps

Esteban Bustamante