Hello @raushan123 -
In AEM as a Cloud Service, direct access to runmodes is not available. Runmodes are primarily used in AEM on-premise installations to define specific configurations and behavior for different environments.
However, Adobe provides an alternative approach for managing environment-specific configurations in AEM as a Cloud Service. The recommended approach is to use Cloud Manager and the Configuration Management feature to handle environment-specific settings.
Here's how to set up environment-specific configurations using Configuration Management in AEM as a Cloud Service:
1. Access Cloud Manager: Log in to Adobe Experience Cloud and navigate to the Cloud Manager console.
2. Configure Configuration Management: In the Pipeline configuration, enable the Configuration Management feature. This allows you to manage environment-specific configurations for your AEM project.
3. Define Configuration Properties: Within the Configuration Management section, define the properties or settings that you want to manage for your AEM project. These properties can be environment-specific, such as database connections, API endpoints, or any other configurations that differ between environments.
4. Create Configuration Sets: Create different configuration sets for each environment, such as Dev, Stage, and Prod. Within each configuration set, you can specify the values for the defined properties.
5. Assign Configuration Sets to Environments: Assign the appropriate configuration set to each environment in your Pipeline. For example, assign the Dev configuration set to the Dev environment, the Stage configuration set to the Stage environment, and so on.
6. Deploy Configuration Sets: When you deploy your AEM project using Cloud Manager, the associated configuration set for each environment will be deployed along with the code. This ensures that the correct configurations are applied to each environment during the deployment process.
Now, once this is done you can retrieve the environment-specific configurations using the ConfigurationManager service in a sling model as below :
import com.adobe.granite.confmgr.Configuration;
import com.adobe.granite.confmgr.ConfigurationManager;
import com.adobe.granite.confmgr.ConfigurationManagerFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Model(adaptables = SlingHttpServletRequest.class)
public class MyModel {
@Inject
private ConfigurationManager configManager;
public String getEnvironmentType() {
Configuration envConfig = configManager.getConfiguration("env-configuration-set");
return envConfig.getProperties().get("envType.property", String.class);
}
}
And later can leverage the same in your HTL code as follows :
<div data-sly-use.model="com.example.MyModel">
<sly data-sly-test="${model.environmentType == 'dev'}">
<!-- Render dev-specific code -->
</sly>
<sly data-sly-test="${model.environmentType == 'prod'}">
<!-- Render prod-specific code -->
</sly>
</div>