class Stax::Cmd::Lambda
Public Instance Methods
code(id)
click to toggle source
# File lib/stax/mixin/lambda.rb, line 59 def code(id) url = Aws::Lambda.code(my.resource(id)) if options[:url] puts url else Tempfile.new([my.stack_name, '.zip']).tap do |file| file.write(open(url).read) file.close puts %x[unzip -p #{file.path}] # unzip all contents to stdout end end end
config(id)
click to toggle source
# File lib/stax/mixin/lambda.rb, line 52 def config(id) cfg = Aws::Lambda.configuration(my.resource(id)) puts YAML.dump(stringify_keys(cfg.to_hash)) end
ls()
click to toggle source
# File lib/stax/mixin/lambda.rb, line 40 def ls debug("Lambda functions for stack #{my.stack_name}") names = stack_lambdas.map(&:physical_resource_id) print_table Aws::Lambda.list.select { |l| names.include?(l.function_name) }.map { |l| size = (l.code_size/1.0.megabyte).round.to_s + 'MB' [l.function_name, l.description, l.runtime, size, l.last_modified] } end
stack_lambdas()
click to toggle source
# File lib/stax/mixin/lambda.rb, line 19 def stack_lambdas Aws::Cfn.resources_by_type(my.stack_name, 'AWS::Lambda::Function') end
test(id)
click to toggle source
# File lib/stax/mixin/lambda.rb, line 89 def test(id) Aws::Lambda.invoke( function_name: my.resource(id), invocation_type: options[:type], log_type: options[:tail] ? 'Tail' : nil, payload: options[:file] ? File.open(options[:file]) : options[:payload], ).tap do |resp| puts resp.status_code warn(resp.function_error) if resp.function_error puts Base64.decode64(resp.log_result) if options[:tail] end end
update(id, file)
click to toggle source
# File lib/stax/mixin/lambda.rb, line 74 def update(id, file) Aws::Lambda.update_code( function_name: my.resource(id), publish: options[:publish], zip_file: zip_thing(file), )&.version.tap do |v| puts "version: #{v}" end end
zip_thing(thing)
click to toggle source
return zip file contents, make it if necessary
# File lib/stax/mixin/lambda.rb, line 24 def zip_thing(thing) if File.directory?(thing) Dir.chdir(thing) do %x[zip -q -r - .] # zip dir contents end elsif thing.match(/\.zip$/i) File.read(thing) # raw zipfile contents elsif File.file?(thing) %x[zip -q -j - #{thing}] # zip a single file else nil end end