Use of Environment Variables in AEMaaCS
Benefits of Environment Variables
Environment variables (EV) offer a host of benefits to users of AEM as a Cloud Service:
- EVs are only required to be configured once and can be updated and deleted when required.
- The value of an EV can be updated at any point in time and take effect immediately without any code changes or deployments.
- The use of EV is the way to separate code from configuration and remove the need to include sensitive information in version control.
- EVs can improve the security of the AEM as a Cloud Service application since they live outside of the code.
Configuring Environment Variable on AEMaaCS
- log-in into the Adobe Cloud Manager.
- Select the Environments tab for the chosen program then select the environment for which you want to create an environment variable in the left navigation panel.
- Select the Configuration tab then select Add to open the Environment Configuration dialog.
- Enter the variable name, value and type. For storing passwords use secret as the type.
- Save the configuration.
Use of EVs in OSGI Configuration
- To use environment variables in your OSGi configuration, the config file should be in .cfg.json format.
- Variables should be written as $[env:<environment variable name>]
- To use secret variables syntax will be as $[secret:server-api-key]
- Default values for EVs can be used, In case of the EV is not found in particular environments. $[env:<environment variable name>;default=<default value>]
Testing EVs in AEM Local Instance
- For testing EVs in the local environment, the code will remain the same.
- Only we need to add environment variables in the local AEM instance running session.
- To add EV in local export the variable just before starting the AEM instance.
- The use of shell script is recommended to start the AEM instance in the local environment.
- Example shell script can be as below –
start.sh
Explore our blogs for an in-depth understanding of various trending topics.