Skip to content

Commit bb92bd3

Browse files
committed
feat: enable usage of AWS SSM to supply environment variables
1 parent 95baab4 commit bb92bd3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lambda_function.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'date'
66
require 'redis'
77
require 'dogapi'
8+
require 'aws-sdk-ssm'
89
require_relative 'lib/slowlog_check'
910

1011
LOGGER = Logger.new($stdout)
@@ -28,6 +29,19 @@ def lambda_handler(event: {}, context: {})
2829
@event = event
2930
log_context
3031

32+
if ENV.fetch('SSM_PATH', false)
33+
resp = Aws::SSM::Client.new().get_parameters_by_path(
34+
path: '/slowlog_check/',
35+
recursive: true,
36+
with_decryption: true
37+
)
38+
resp.parameters.each do |parameter|
39+
name = File.basename(parameter.name)
40+
LOGGER.info "Setting parameter: #{name} from SSM."
41+
ENV[name] = parameter.value
42+
end
43+
end
44+
3145
unless defined? @slowlog_check
3246
@slowlog_check = SlowlogCheck.new(
3347
ddog: Dogapi::Client.new(
@@ -40,7 +54,7 @@ def lambda_handler(event: {}, context: {})
4054
),
4155
namespace: ENV.fetch('NAMESPACE'),
4256
env: ENV.fetch('ENV'),
43-
metricname: 'scribddev.redis.slowlog.micros'
57+
metricname: ENV.fetch('METRICNAME', 'redis.slowlog.micros')
4458
)
4559

4660
@slowlog_check.update_metadatas

0 commit comments

Comments
 (0)