Expand my Community achievements bar.

How to add custom variables per environment/namespace in Adobe I/O Runtime (commerce-cif-graphql-integration-reference)

Avatar

Level 1

I am new in the AIO world, so for my proof of concept I am using and modifying the CIF reference project commerce-cif-graphql-integration-reference, but I am trying to create custom configuration values to connect to a 3rd party REST API. The goal is to have separate values per environment, for example:

 

For namespace mycoolnamespace1:

MY_API_URL = http://dev.mycookapi.com/rest/something
MY_API_KEY = DEV123

 

For namespace mycoolnamespace2:

MY_API_URL = http://qa.mycookapi.com/rest/something
MY_API_KEY = QA123

 

For namepsace prod

MY_API_URL = http://prod.mycookapi.com/rest/something
MY_API_KEY = PROD123

 

Then have these variables available in 'params' to be used by my actions. However I don't know how to achieve this. Could some good soul point me to the right direction?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

3 Replies

Avatar

Level 1

A quick update, I think I was able to partially fix the problem as follows:

 

In my .env file I just added my custom property SAMPLE_PRODUCT_URL

AIO_runtime_auth=[my auth]
AIO_runtime_namespace=[my namespace]
AIO_runtime_apihost=https://adobeioruntime.net
SERVICE_API_KEY=

#One debug mode to rule them all
LOG_LEVEL=debug

#Other stuff
SAMPLE_PRODUCT_URL=https://[my url here]/sample.json

Then in the file app.config.yaml I just added the property in the inputs section for my action (sampleproducturl: $SAMPLE_PRODUCT_URL)

 

application:
  actions: actions
  web: web-src
  runtimeManifest:
    packages:
      commerce-cif-graphql-integration:
        license: Apache-2.0
        actions:
          dispatcher:
            function: actions/local/dispatcher.js
            web: 'yes'
            runtime: 'nodejs:14'
            inputs:
              LOG_LEVEL: debug
              use-aio-cache: false # number of seconds for caching; set to false or remove to disable caching
              url: https://jafet-is-cool.com
              sampleproducturl: $SAMPLE_PRODUCT_URL
              remoteSchemas: # Action with smaller order has "merge priority" in schema conflicts
                cart:
                  order: 20
                  action: commerce-cif-graphql-integration/cart
            annotations:
              provide-api-key: true
              final: true

At first I didn't see any changes (sampleproducturl was not present in the params) so I ran aio app undeploy and then aio app deploy and that did the trick.

 

Now the missing part is: How to add separate environment variables per namespace?  In the regular AEM could there is a section to add environment variables but that option is not present for adobe runtime. any ideas?

 

Avatar

Level 4

Hi @jafetsanchez 

 

Yes -- environment variables can be passed in using default params. You've done it correctly in your second reply and you could read more about it here - https://github.com/apache/openwhisk-wskdeploy/blob/master/docs/wskdeploy_action_fixed_parms.md#actio....

 

If you are looking to set separate env variables in different namespaces, I would suggest keeping multiple copies of app.config.yaml and .env file that map to the environments you are trying to deploy to. When you are switching projects / namespaces, use the app.config.yaml and .env file that match the environment you are trying to deploy to.

 

Hope this helps,

Sarah

Avatar

Level 1

In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable. Click Edit to modify an existing environment variable.