ExtConfigProvider v1.0.0 ExtConfigProvider View Source

Flexible Config Provider for e.g. AWS Parameter Store/Secrets Manager

Fetch your configuration at the start of the application from AWS Parameter Store or the Secrets Manager. The format of your secrets can be json/toml or any other format. There's also flexibility in how the secrets are applied to your config.

Installation

The package can be installed by adding aws_config_provider to your list of dependencies in mix.exs:

def deps do
  [
    {:aws_config_provider, "~> 1.0.0"}
  ]
end

The AWS Parameter Store/Secrets Manager are packaged config providers. They need ExAws to be configured and have the right IAM permissions to work.

Adding a config provider

  def project do
    [
      app: :example,
      ...
      releases: [
        example: [
          config_providers: [{ExtConfigProvider, [path: "parameter_name"]}]
        ]
      ]
    ]
  end

The config provider can take several options. See ExtConfigProvider.init/1

A macro can also be used to build a config provider

  defmodule Example.ConfigProvider do
    use ExtConfigProvider,
      parser: ExtConfigProvider.Parser.String,
      transformer: ExtConfigProvider.Transformer.Value,
      merge_strategy: ExtConfigProvider.MergeStrategy.Path,
      config_path: [:app, :secret]
  end

You can add this config provider in the usual fashion:

  releases: [
    example: [
      config_providers: [{Example.ConfigProvider, [path: "parameter_name"]}]
    ]
  ]

Inspired by https://github.com/christopherlai/secrets_manager_provider

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/aws_config_provider.

Link to this section Summary

Functions

Accepts list of opts

Link to this section Functions

Accepts list of opts:

  • :path -- (required) the key of the parameter. If supplied a tuple {:env, "env"}, the specified env var will be used as the path.
  • :parser -- how to parse the retrieved parameter, defaults to Jason
  • :transformer -- transform the parsed value to a configuration, defaults to ExtConfigProvider.Transformer.Default
  • :merge_strategy -- how to apply the configuration to the existing configuration, defaults to ExtConfigProvider.MergeStrategy.Default
  • :client -- Which client to use to get the parameter, defaults to ExtConfigProvider.Client.ParameterStore
  • :client_opts -- keyword list to pass to the client to override e.g. region