How to manage environment-specific configurations?
What is the recommended way to manage environment-specific configurations (like API endpoints or feature flags) in AEM as a Cloud Service?
What is the recommended way to manage environment-specific configurations (like API endpoints or feature flags) in AEM as a Cloud Service?
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:
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.
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).
Never use if(runmode == "dev") logic in code.
Instead, inject configuration using OSGi or CAC, and keep code environment-agnostic.
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!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.