Sha256: 7b5bae43e12eafebe6f8f9b2bf79287e2d7ad58f36cddce6d9a506e7d94581d2

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

#!/usr/bin/env ruby

env = {}

if ENV.has_key?('SSM_KEY_PATH')
  require 'aws-sdk-ssm'

  puts 'Injecting application secrets...'

  begin
    client = Aws::SSM::Client.new

    next_token = nil
    loop do
      secrets = client.get_parameters_by_path(
        path: ENV.fetch('SSM_KEY_PATH'),
        with_decryption: true,
        next_token: next_token
      )

      secrets.parameters.map do |parameter|
        key = parameter.name.split('/').last
        value = parameter.value
        env[key] = value
      end

      next_token = secrets.next_token
      break unless next_token

      sleep 1 # don't overrun the API rate limit
    end
  rescue Aws::Errors::MissingRegionError
    puts 'Error: Missing AWS Region'
    exit 1
  rescue Aws::Errors::MissingCredentialsError
    puts 'Error: Missing AWS Credentials'
    exit 2
  end
end

exec env, *ARGV

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cai-ecs-entrypoint-1.1.0 bin/ssm-entrypoint