As an AEM developer developing for the AEMaaCS SDK, it’s essential to have a local environment properly set up for development purposes. You may encounter environment-specific and secret variables in your OSGI configuration files. As an AEM developer trying to familiarize new features of the AEMaaCS SDK development environment, setting up environment-specific and secret variables is non-trivial at first. Once you have done it once, it will be much easier to move forward.
In this article, I will show you how to set up environment-specific and secret variables. If you would like to understand when to use environment-specific and secret variables effectively, check out the official AEM Adobe git documentation. At the end of this article, you are equipped to run your AEM local development environment with environment-specific and secret variables!
One last thing, it looks like only AEMaaCS SDK has environment-specific and secret variables feature enabled for OSGI configurations.
Examples of what OSGI configurations would look like with environment and secret variables set in your code base:
Environment-specific variable
high-level use-case: Values that are specific to a particular environment and may vary between different development environments cannot be targeted accurately by run mode, as AEMaaCS only has a single development run mode. For instance:
1 2 3 | { "url": "$[env:SERVER_API_URL]" } |
Secret variable
high-level use-case: Sensitive information, such as confidential data or authentication credentials, should not be stored in Git repositories due to security concerns. For instance:
1 2 3 | { "api-key": "$[secret:SERVER_API_KEY]" } |
Example of an OSGI configuration with the combination of the environment-specific and secret variables being used:
1 2 3 4 5 | { "connection.timeout": 1000, "api-key": "$[secret:SERVER_API_KEY]", "url": "$[env:SERVER_API_URL]" } |
1 2 3 4 5 6 | { "connection.timeout": 1000, "api-key": "$[secret:SERVER_API_KEY;default=https://api.sourcedcode.com"]", "url": "$[env:SERVER_API_URL;default=23u1kn1jbkjs789fds8f_ewrqasd]" } From the <a href="https://github.com/AdobeDocs/experience-manager-cloud-service.en/blob/main/help/implementing/deploying/configuring-osgi.md" rel="noopener" target="_blank">documentation</a>, it looks like only AEMaaCS has environment-specific and secret variables feature enabled for OSGI configurations. |
So how we can actually set these environments and secret variables into AEM? Well, it’s simple. We will be using a Linux environment to set this up. In the examples below, we will be setting up one environment-specific variable and one secret variable.
- $[env:SERVER_API_URL]
- $[secret:SERVER_API_KEY]
1 2 3 4 5 | { "connection.timeout": 1000, "url": "$[env:SERVER_API_URL]" "api-key": "$[secret:SERVER_API_KEY]", } |
1. set AEM Environment variables on local AEM instance
- Close down your local AEM environment.
- open git bash or terminal.
- cd to the AEM folder, where the executable jar file exists.
- run export SERVER_API_URL=https://api.sourcedcode.com
- run echo ${SERVER_API_URL}// you should see the environment variable being set as this call will echo out what the environment variable is for SERVER_API_URL.
- now restart your local AEM environment.
- done.
2. set AEM Secret variables on local AEM instance
- Close down your local AEM environment.
- open git bash or terminal.
- cd to the AEM folder, where the executable jar file exists.
- run vim ./crx-quickstart/conf/quickstart.properties
- add this to the last line org.apache.felix.configadmin.plugin.interpolation.secretsdir=${sling.home}/secretsdir
- save in vim.
- run mkdir ./crx-quickstart/secretsdir
- run cd ./crx-quickstart/secretsdir
- run echo “23u1kn1jbkjs789fds8f_ewrqasd” > SERVER_API_KEY
- repeat the step-9 to add more secret variables into your AEM local environment. run echo “secret_value” > secret_key
- You may have more than 1 secret variable stored in the secretsdir folder:
- now restart your local AEM environment.
- done.
I was trying this for windows the secret variables are not taking. Do I need to change anything to make it work in windows machine?
crx-quickstart/conf/sling.properties – it is working after I added in this file
Cool, I’m glad that you got it to work!