Class: Awful::Lambda

Inherits:
Cli show all
Defined in:
lib/awful/lambda.rb

Instance Method Summary collapse

Methods inherited from Cli

#initialize

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#code(name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/awful/lambda.rb', line 87

def code(name)
  url = lambda.get_function(function_name: name).code.location
  if options[:url]
    url
  else
    zipdata = open(url).read
    file = Tempfile.open(['awful', '.zip'])
    file.write(zipdata)
    file.close
    %x[unzip -p #{file.path}] # unzip all contents to stdout
  end.tap do |output|
    puts output
  end
end

#create(name = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/awful/lambda.rb', line 43

def create(name = nil)
  opt = load_cfg
  opt[:function_name] = name unless name.nil?
  opt[:code][:zip_file] = zip_thing(opt[:code][:zip_file])
  whitelist = %i[function_name runtime role handler description timeout memory_size code]
  lambda.create_function(only_keys_matching(opt, whitelist)).tap do |response|
    puts YAML.dump(stringify_keys(response.to_hash))
  end
end

#delete(name) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/awful/lambda.rb', line 103

def delete(name)
  if yes? "Really delete lambda function #{name}?", :yellow
    lambda.delete_function(function_name: name).tap do
      puts "deleted #{name}"
    end
  end
end

#dump(name) ⇒ Object



79
80
81
82
83
# File 'lib/awful/lambda.rb', line 79

def dump(name)
  lambda.get_function_configuration(function_name: name).tap do |h|
    puts YAML.dump(stringify_keys(h.to_hash))
  end
end

#eventsObject

see lambda_events.rb for subcommands



112
# File 'lib/awful/lambda.rb', line 112

desc 'events', 'subcommands for lambda event mappings'

#ls(name = /./) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/awful/lambda.rb', line 28

def ls(name = /./)
  lambda.list_functions.functions.select do |function|
    function.function_name.match(name)
  end.tap do |functions|
    if options[:long]
      print_table functions.map { |f| [f.function_name, f.description, f.last_modified] }.sort
    elsif options[:arns]
      puts functions.map(&:function_arn).sort
    else
      puts functions.map(&:function_name).sort
    end
  end
end

#update(name = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/awful/lambda.rb', line 55

def update(name = nil)
  opt = load_cfg
  opt[:function_name] = name unless name.nil?

  ## update configuration
  whitelist = %i[function_name role handler description timeout memory_size]
  response = lambda.update_function_configuration(only_keys_matching(opt, whitelist)).to_hash

  ## update code
  opt[:code] = {zip_file: options[:zip_file]} if options[:zip_file]
  unless opt.fetch(:code, {}).empty?
    code = opt[:code].merge({function_name: opt[:function_name]})
    code[:zip_file] = zip_thing(code[:zip_file]) if code[:zip_file]
    r = lambda.update_function_code(code)
    response = response.merge(r.to_hash)
  end

  ## return combined response
  response.tap do |resp|
    puts YAML.dump(stringify_keys(resp))
  end
end