awful 0.0.40 → 0.0.41

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cff7a37a1cddab21100015c4de83e509aea63008
4
- data.tar.gz: 3fb74a3ece147fe4b09dcdf39a440286b782e27a
3
+ metadata.gz: 83b5b77becbd5727d13cc06dedbba8c9b4ad273c
4
+ data.tar.gz: 5cd0d08da6544763f9f5f660434000cb11db8b72
5
5
  SHA512:
6
- metadata.gz: e8f2490caa2984334e6fe299e2cd12bea7f311e6cd4a183792992115b89f225d26e65c1755a043f01bc83efd011921f18ea02c01fc21b1dec699e37f60aa6876
7
- data.tar.gz: 6d1575b950379b68bcf4d04fe73a16d7544d983b45aa1c05af6f3e495c3cda887604d83392da766518c51510dbbdd2ad78e084ba8589d76b606446f2694cc9bf
6
+ metadata.gz: e0faed7b9c2f5afdeb582b65a96195dcde7fd7e9dd951526bd94a74661236a170f53fc23b705d3d44e4712456147ab72adfcc44b980c5756ea4c73fb5dfa650f
7
+ data.tar.gz: 3239f983c1fd56f39a8e2fff742ee36118f35f03baf2a49a608798dc73863c44d299f4c1aa9d4b9f9d2819df81df7bca9cc9890ed1a80a012c9c697ee4ab5b25
data/bin/lambda ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ #-*- mode: ruby; -*-
3
+
4
+ require 'awful'
5
+ require 'awful/lambda'
6
+
7
+ Awful::Lambda.start(ARGV)
@@ -0,0 +1,134 @@
1
+ require 'open-uri'
2
+ require 'tempfile'
3
+
4
+ module Awful
5
+
6
+ class Lambda < Cli
7
+
8
+ no_commands do
9
+ def lambda
10
+ @lambda ||= Aws::Lambda::Client.new
11
+ end
12
+
13
+ ## return zip file contents, make it if necessary
14
+ def zip_thing(thing)
15
+ if File.directory?(thing)
16
+ Dir.chdir(thing) do
17
+ %x[zip -q -r - .] # zip dir contents
18
+ end
19
+ elsif thing.match(/\.zip$/i)
20
+ File.read(thing) # raw zipfile contents
21
+ elsif File.file?(thing)
22
+ %x[zip -q -j - #{thing}] # zip a single file
23
+ else
24
+ nil
25
+ end
26
+ end
27
+ end
28
+
29
+ desc 'ls NAME', 'list lambda functions matching NAME pattern'
30
+ method_option :long, aliases: '-l', default: false, desc: 'Long listing'
31
+ method_option :arns, aliases: '-a', default: false, desc: 'List ARNs for functions'
32
+ def ls(name = /./)
33
+ lambda.list_functions.functions.select do |function|
34
+ function.function_name.match(name)
35
+ end.tap do |functions|
36
+ if options[:long]
37
+ print_table functions.map { |f| [f.function_name, f.description, f.last_modified] }.sort
38
+ elsif options[:arns]
39
+ puts functions.map(&:function_arn).sort
40
+ else
41
+ puts functions.map(&:function_name).sort
42
+ end
43
+ end
44
+ end
45
+
46
+ desc 'create', 'create a new lambda function'
47
+ def create(name = nil)
48
+ opt = load_cfg
49
+ opt[:function_name] = name unless name.nil?
50
+ opt[:code][:zip_file] = zip_thing(opt[:code][:zip_file])
51
+ whitelist = %i[function_name runtime role handler description timeout memory_size code]
52
+ lambda.create_function(only_keys_matching(opt, whitelist)).tap do |response|
53
+ puts YAML.dump(stringify_keys(response.to_hash))
54
+ end
55
+ end
56
+
57
+ desc 'update [NAME]', 'update lambda function config [and code]'
58
+ method_option :zip_file, aliases: '-z', default: false, desc: 'Update code zip file (creates if necessary)'
59
+ def update(name = nil)
60
+ opt = load_cfg
61
+ opt[:function_name] = name unless name.nil?
62
+
63
+ ## update configuration
64
+ whitelist = %i[function_name role handler description timeout memory_size]
65
+ response = lambda.update_function_configuration(only_keys_matching(opt, whitelist)).to_hash
66
+
67
+ ## update code
68
+ opt[:code] = {zip_file: zip_thing(options[:zip_file])} if options[:zip_file]
69
+ unless opt.fetch(:code, {}).empty?
70
+ r = lambda.update_function_code(opt[:code].merge({function_name: opt[:function_name]}))
71
+ response = response.merge(r.to_hash)
72
+ end
73
+
74
+ ## return combined response
75
+ response.tap do |resp|
76
+ puts YAML.dump(stringify_keys(resp))
77
+ end
78
+ end
79
+
80
+ desc 'dump NAME', 'get configuration of lambda function NAME'
81
+ def dump(name)
82
+ lambda.get_function_configuration(function_name: name).tap do |h|
83
+ puts YAML.dump(stringify_keys(h.to_hash))
84
+ end
85
+ end
86
+
87
+ desc 'code NAME', 'get code for lambda function NAME'
88
+ method_option :url, aliases: '-u', default: false, desc: 'Return just URL instead of downloading code'
89
+ def code(name)
90
+ url = lambda.get_function(function_name: name).code.location
91
+ if options[:url]
92
+ url
93
+ else
94
+ zipdata = open(url).read
95
+ file = Tempfile.open(['awful', '.zip'])
96
+ file.write(zipdata)
97
+ file.close
98
+ %x[unzip -p #{file.path}] # unzip all contents to stdout
99
+ end.tap do |output|
100
+ puts output
101
+ end
102
+ end
103
+
104
+ desc 'delete NAME', 'delete lambda function NAME'
105
+ def delete(name)
106
+ if yes? "Really delete lambda function #{name}?", :yellow
107
+ lambda.delete_function(function_name: name).tap do
108
+ puts "deleted #{name}"
109
+ end
110
+ end
111
+ end
112
+
113
+ desc 'events NAME', 'list event source mappings for lambda function NAME'
114
+ method_option :long, aliases: '-l', default: false, desc: 'Long listing'
115
+ method_option :create, aliases: '-c', default: nil, desc: 'Create event source mapping with given ARN'
116
+ def events(name)
117
+ if options[:create]
118
+ lambda.create_event_source_mapping(function_name: name, event_source_arn: options[:create], starting_position: 'LATEST').tap do |response|
119
+ puts YAML.dump(stringify_keys(response.to_hash))
120
+ end
121
+ else # list
122
+ lambda.list_event_source_mappings(function_name: name).event_source_mappings.tap do |sources|
123
+ if options[:long]
124
+ print_table sources.map { |s| [s.event_source_arn, s.state, "Batch size: #{s.batch_size}, Last result: #{s.last_processing_result}", s.last_modified] }
125
+ else
126
+ puts sources.map(&:event_source_arn)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+ end
data/lib/awful/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = "0.0.40"
2
+ VERSION = "0.0.41"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.40
4
+ version: 0.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ executables:
92
92
  - dynstr
93
93
  - ec2
94
94
  - elb
95
+ - lambda
95
96
  - lc
96
97
  - r53
97
98
  - rds
@@ -118,6 +119,7 @@ files:
118
119
  - bin/dynstr
119
120
  - bin/ec2
120
121
  - bin/elb
122
+ - bin/lambda
121
123
  - bin/lc
122
124
  - bin/r53
123
125
  - bin/rds
@@ -136,6 +138,7 @@ files:
136
138
  - lib/awful/dynamodb_streams.rb
137
139
  - lib/awful/ec2.rb
138
140
  - lib/awful/elb.rb
141
+ - lib/awful/lambda.rb
139
142
  - lib/awful/launch_config.rb
140
143
  - lib/awful/rds.rb
141
144
  - lib/awful/route53.rb
@@ -166,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
169
  version: '0'
167
170
  requirements: []
168
171
  rubyforge_project:
169
- rubygems_version: 2.2.2
172
+ rubygems_version: 2.2.5
170
173
  signing_key:
171
174
  specification_version: 4
172
175
  summary: Simple AWS command-line tool.