Class: Sfn::AwsCli

Inherits:
Object
  • Object
show all
Defined in:
lib/sfn/aws_cli.rb

Defined Under Namespace

Classes: ExecutionError

Class Method Summary collapse

Class Method Details

.run(mod, command, params, key = nil, debug_info = '') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sfn/aws_cli.rb', line 9

def self.run(mod, command, params, key = nil, debug_info = '')
  cmd = "#{Sfn.configuration.aws_command || 'aws'} #{mod} #{command} \
                  --endpoint #{Sfn.configuration.aws_endpoint} \
                  #{params.map do |k, v|
                    "--#{k}=#{v}"
                  end.join(' ')} \
                  --no-cli-pager"
  if command == 'get-execution-history'
    stdout = `#{cmd}`
  else
    stdout, stderr, _status = Open3.capture3(cmd)
    raise raise ExecutionError, "#{stderr.strip}\n#{debug_info}" unless stderr.strip.empty?
  end

  unless key.nil?
    data = JSON.parse(stdout)
    return data[key].strip if data.key?(key)
  end

  stdout
end