{"id":57799,"date":"2023-08-03T16:28:09","date_gmt":"2023-08-03T10:58:09","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57799"},"modified":"2024-06-10T15:37:13","modified_gmt":"2024-06-10T10:07:13","slug":"use-of-environment-variables-in-aemaacs","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/use-of-environment-variables-in-aemaacs\/","title":{"rendered":"Use of Environment Variables in AEMaaCS"},"content":{"rendered":"<h2><strong>Benefits of Environment Variables<\/strong><\/h2>\n<h3><span style=\"font-weight: 400;\">Environment variables (EV) offer a host of benefits to users of AEM as a Cloud Service:<\/span><\/h3>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">EVs are only required to be configured once and can be updated and deleted when required.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The value of an EV can be updated at any point in time and take effect immediately without any code changes or deployments.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The use of EV is the way to separate code from configuration and remove the need to include sensitive information in version control.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">EVs can improve the security of the AEM as a Cloud Service application since they live outside of the code.<\/span><\/li>\n<\/ol>\n<h3><\/h3>\n<h2><strong>Configuring Environment Variable on AEMaaCS<\/strong><\/h2>\n<ol>\n<li>log-in into the Adobe Cloud Manager.<\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Select the <\/span><b>Environments<\/b><span style=\"font-weight: 400;\"> tab for the chosen program then select the environment for which you want to create an environment variable in the left navigation panel.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Select the <\/span><b>Configuration<\/b><span style=\"font-weight: 400;\"> tab then select <\/span><b>Add<\/b><span style=\"font-weight: 400;\"> to open the <\/span><b>Environment Configuration<\/b><span style=\"font-weight: 400;\"> dialog.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Enter the variable name, value and type. For storing passwords use <\/span><i><span style=\"font-weight: 400;\">secret<\/span><\/i><span style=\"font-weight: 400;\"> as the type.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Save the configuration.<\/span><\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57902\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/08\/cloud-config-1.png\" alt=\"\" width=\"1161\" height=\"451\" \/><\/p>\n<h2><strong>Use of EVs in OSGI Configuration\u00a0<\/strong><\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57904\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM.png\" alt=\"\" width=\"566\" height=\"145\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM.png 1538w, \/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM-300x77.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM-1024x262.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM-768x197.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM-1536x393.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.54.34-PM-624x160.png 624w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To use environment variables in your OSGi configuration, the config file should be in <\/span><strong><i>.cfg.json<\/i><\/strong><span style=\"font-weight: 400;\"> format.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Variables should be written as <\/span><strong>$[env:&lt;environment variable name&gt;]\u00a0\u00a0<\/strong><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To use secret variables syntax will be as <\/span><span style=\"font-weight: 400;\">$[secret:server-api-key]<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Default values for EVs can be used, In case of the EV is not found in particular environments. <\/span><strong>$[env:&lt;environment variable name&gt;;default=&lt;default value&gt;]<\/strong><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2><strong>Testing EVs in AEM Local Instance<\/strong><\/h2>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">For testing EVs in the local environment, the code will remain the same.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Only we need to add environment variables in the local AEM instance running session.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To add EV in local export the variable just before starting the AEM instance.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The use of shell script is recommended to start the AEM instance in the local environment.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Example shell script can be as below &#8211;<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><b>start.sh<\/b><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57903\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/08\/Screenshot-2023-08-03-at-2.52.15-PM.png\" alt=\"\" width=\"585\" height=\"72\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Explore our\u00a0<a href=\"https:\/\/www.tothenew.com\/blog\/\">blogs<\/a> for an in-depth understanding of various trending topics.<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1212,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":854},"categories":[5868],"tags":[5319],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57799"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1212"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57799"}],"version-history":[{"count":5,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57799\/revisions"}],"predecessor-version":[{"id":58375,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57799\/revisions\/58375"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}