Skip to content

Instantly share code, notes, and snippets.

@kenpropel
Created March 22, 2024 05:23
Show Gist options
  • Save kenpropel/710c470b18aed129e971d4d71461ca2f to your computer and use it in GitHub Desktop.
Save kenpropel/710c470b18aed129e971d4d71461ca2f to your computer and use it in GitHub Desktop.
Using AWS SSM Parameter Store to load configuration in Ruby
require 'aws-sdk-ssm'
require_relative './neko-logger'
L = Neko::Logger.logger
SSMPS_KEY_PATH = '/config/path/'
def config
# Skip if config was loaded within the last hour
if @config_loaded.nil? || (Time.now - @config_loaded > 3600)
L.info('Loading config from SSMPS')
@config = {}
ssm = Aws::SSM::Client.new
ps_path = {
path: SSMPS_KEY_PATH,
recursive: true,
with_decryption: true,
}
ssm.get_parameters_by_path(ps_path).parameters.each do |prm|
k = prm[:name][SSMPS_KEY_PATH.length..].gsub(/\//,'_').to_sym
@config[k] = prm[:value]
end
@config_loaded = Time.now
L.debug("Config loaded #{@config_loaded}")
end
@config
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment