-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Johann edited this page Dec 2, 2018
·
1 revision
This is the SSM adapter for knowledge gem. It allows you to fetch your configuration variables on AWS SSM service.
By default, the SSM client is instantiate using current AWS config.
See the official Aws::SSM::Client#initialize documentation for more details.
If you need to instantiate yourself the client to pass specific params, see the section below.
require 'knowledge/ssm'
knowledge = Knowledge::Learner.new
knowledge.variables = { ssm: { my_secret: 'path/to/secret' } }
knowledge.use(name: :ssm)
knowledge.add_adapter_params(adapter: :ssm, params: { root_path: '/project' })
knowledge.gather!
Knowledge::Configuration.my_secret # "Secret value"
require 'knowledge/ssm'
knowledge = Knowledge::Learner.new
knowledge.variables = { ssm: { my_secret: 'path/to/secret' } }
ssm_client = Aws::SSM::Client.new # Instanciate it with your own config
knowledge.use(name: :ssm)
knowledge.add_adapter_params(adapter: :ssm, params: { root_path: '/project', client: ssm_client })
# Will use your SSM Client to fetch variables
knowledge.gather!
Knowledge::Configuration.my_secret # "Secret value"
All errors generated by Aws::SSM::Client are rescued and re-raised as Knowledge::SsmError
.
The 3 main errors you can face are:
- Aws::SSM::Errors::AccessDeniedException
- Aws::SSM::Errors::UnrecognozedClientException
- Aws::SSM::Errors::ParameterNotFound
You can chose not to raise in case of Aws::SSM::Errors::ParameterNotFound
.
To do so, just pass raise_on_parameter_not_found
to false as custom param for the adapter:
require 'knowledge/ssm'
knowledge = Knowledge::Learner.new
knowledge.variables = { ssm: { my_secret: 'path/to/unexisting/param' } }
knowledge.use(name: :ssm)
knowledge.add_adapter_params(adapter: :ssm, params: { raise_on_parameter_not_found: false })
knowledge.gather! # Will not raise because of the unexisting param
Knowledge::Configuration.my_secret # "Secret value"