How to externalize the configuration

I am using the Kalix Java to create the event sourced entity with kalix action and view. One of the requirement is to create an action for handling the API request to backend service for data verification. I want to create a configurable and reusable API client, so that we can define the connectivity attributes in the CI/CD per each environment (e.g. DEV, UAT, production).

Thus, may I know how we can externalize the configuration for Kalix application so that we can define the configuration in application.conf or even in environment variables instead of coding in the source?

1 Like

What is currently available for deployment specific configuration is environment variables. They can be defined with the --env MYENV=abc parameter to the kalix CLI when deploying a service.

For Java/Scala services you can pick up environment variables in application.conf like so:

my-service {
  some-setting = "default value"
  some-setting = ${?MYENV}

This means the environment variable value is picked up if set, if it is not set the default value is used.

You can of course also read the environment variables directly in your Java/Scala logic in a way that suits your use case (for example to load completely different config files).