lambchop 0.0.13 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +44 -5
- data/bin/lambchop +0 -1
- data/bin/lambchop-cat +13 -4
- data/lambchop.gemspec +1 -1
- data/lib/lambchop.rb +1 -0
- data/lib/lambchop/cat.rb +27 -2
- data/lib/lambchop/client.rb +18 -7
- data/lib/lambchop/diff.rb +1 -1
- data/lib/lambchop/dump.rb +1 -2
- data/lib/lambchop/utils.rb +4 -0
- data/lib/lambchop/version.rb +1 -1
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 767cf7d18e8ec7aaa5aae1d17b9b0746b3915404
|
4
|
+
data.tar.gz: f11c95fb9f7cac65425c15ab9753bc45141ff120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0852b44385802c6f1ffd2ec6277568dc9e43b53b9c4e983bbb83dd54c4ddcdce884d1544f6d7022e54e340702e0556a2bce7e18f638b76b3d871c624d669ec7
|
7
|
+
data.tar.gz: d585b6dc88ea810b56936f9aa9ad641d5dd747a5aed3706054f5040c12d73b1166b0e62c39194549035f3936d8c939ffd7c108f1f3446c0944bdfec8db802b66
|
data/README.md
CHANGED
@@ -33,7 +33,6 @@ $ cat test.js
|
|
33
33
|
/*
|
34
34
|
function_name: test # default: file name without ext
|
35
35
|
runtime: nodejs # default: nodejs
|
36
|
-
mode: event # default: event
|
37
36
|
description: '' # default: (empty)
|
38
37
|
timeout: 3 # default: 3
|
39
38
|
memory_size: 128 # default: 128
|
@@ -48,7 +47,7 @@ exports.handler = function(event, context) {
|
|
48
47
|
console.log('value1 = ' + event.key1);
|
49
48
|
console.log('value2 = ' + event.key2);
|
50
49
|
console.log('value3 = ' + event.key3);
|
51
|
-
context.
|
50
|
+
context.success('Hello World');
|
52
51
|
};
|
53
52
|
|
54
53
|
$ ./test.js
|
@@ -64,8 +63,11 @@ $ export AWS_REGION=us-east-1
|
|
64
63
|
$ lambchop-cat
|
65
64
|
usage: lambchop-cat <function-name>
|
66
65
|
|
67
|
-
$ lambchop-cat
|
68
66
|
$ echo '{"key1":100, "key2":200, "key3":300}' | lambchop-cat test
|
67
|
+
---
|
68
|
+
status_code: 200
|
69
|
+
function_error:
|
70
|
+
payload: '"Hello World"'
|
69
71
|
```
|
70
72
|
|
71
73
|
**Terminal 1**:
|
@@ -80,6 +82,44 @@ END RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
80
82
|
REPORT RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Duration: 117.54 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 9 MB
|
81
83
|
```
|
82
84
|
|
85
|
+
### Invoke async
|
86
|
+
|
87
|
+
```sh
|
88
|
+
$ echo '{"key1":100, "key2":200, "key3":300}' | lambchop-cat test -t event
|
89
|
+
---
|
90
|
+
status_code: 202
|
91
|
+
function_error:
|
92
|
+
payload: ''
|
93
|
+
```
|
94
|
+
|
95
|
+
### Invoke with tail
|
96
|
+
|
97
|
+
```sh
|
98
|
+
$ echo '{"key1":100, "key2":200, "key3":300}' | lambchop-cat test -l tail
|
99
|
+
status_code: 200
|
100
|
+
function_error:
|
101
|
+
payload: '"Hello world!"'
|
102
|
+
log_result: |-
|
103
|
+
2014-11-23T08:06:53.212Z xxxxxxxxxxxxxxxx Loading event
|
104
|
+
START RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
105
|
+
2014-11-23T08:06:53.330Z xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx value1 = 100
|
106
|
+
2014-11-23T08:06:53.330Z xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx value3 = 300
|
107
|
+
2014-11-23T08:06:53.330Z xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx value2 = 200
|
108
|
+
END RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
109
|
+
REPORT RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Duration: 117.54 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 9 MB
|
110
|
+
```
|
111
|
+
|
112
|
+
|
113
|
+
### DryRun
|
114
|
+
|
115
|
+
```sh
|
116
|
+
$ echo '{"key1":100, "key2":200, "key3":300}' | lambchop-cat test -t dry_run
|
117
|
+
---
|
118
|
+
status_code: 204
|
119
|
+
function_error:
|
120
|
+
payload: ''
|
121
|
+
```
|
122
|
+
|
83
123
|
## Dump function
|
84
124
|
|
85
125
|
```sh
|
@@ -93,7 +133,6 @@ function_name: test
|
|
93
133
|
runtime: nodejs
|
94
134
|
role: arn:aws:iam::NNNNNNNNNNNN:role/lambda_exec_role
|
95
135
|
handler: test.handler
|
96
|
-
mode: event
|
97
136
|
description: ''
|
98
137
|
timeout: 3
|
99
138
|
memory_size: 128
|
@@ -104,7 +143,7 @@ exports.handler = function(event, context) {
|
|
104
143
|
console.log('value1 = ' + event.key1);
|
105
144
|
console.log('value2 = ' + event.key2);
|
106
145
|
console.log('value3 = ' + event.key3);
|
107
|
-
context.
|
146
|
+
context.success('Hello World');
|
108
147
|
};
|
109
148
|
```
|
110
149
|
|
data/bin/lambchop
CHANGED
@@ -22,7 +22,6 @@ Please run the lambda script that has the following header:
|
|
22
22
|
/*
|
23
23
|
function_name: any_name # default: file name without ext
|
24
24
|
runtime: nodejs # default: nodejs
|
25
|
-
mode: event # default: event
|
26
25
|
description: any_desc # default: (empty)
|
27
26
|
timeout: 3 # default: 3
|
28
27
|
memory_size: 128 # default: 128
|
data/bin/lambchop-cat
CHANGED
@@ -2,12 +2,21 @@
|
|
2
2
|
$: << File.expand_path("#{File.dirname __FILE__}/../lib")
|
3
3
|
require 'rubygems'
|
4
4
|
require 'lambchop'
|
5
|
+
require 'optparse'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
Version = Lambchop::VERSION
|
8
|
+
|
9
|
+
options = {
|
10
|
+
:invocation_type => :request_response,
|
11
|
+
:log_type => :none
|
12
|
+
}
|
13
|
+
|
14
|
+
ARGV.options do |opt|
|
15
|
+
opt.on('-t', '--invocation-type=TYPE', [:request_response, :event, :dry_run]) {|v| options[:invocation_type] = v }
|
16
|
+
opt.on('-l', '--log-type=TYPE', [:none, :tail]) {|v| options[:log_type] = v }
|
17
|
+
opt.parse!
|
9
18
|
end
|
10
19
|
|
11
20
|
Lambchop::Utils.with_error_logging do
|
12
|
-
Lambchop::Cat.cat(ARGV[0], $stdin)
|
21
|
+
Lambchop::Cat.cat(ARGV[0], $stdin, options)
|
13
22
|
end
|
data/lambchop.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
|
22
|
-
spec.add_dependency 'aws-sdk-core', '~> 2.
|
22
|
+
spec.add_dependency 'aws-sdk-core', '~> 2.1'
|
23
23
|
spec.add_dependency 'rubyzip', '>= 1.0.0'
|
24
24
|
spec.add_dependency 'diffy'
|
25
25
|
spec.add_development_dependency 'bundler'
|
data/lib/lambchop.rb
CHANGED
data/lib/lambchop/cat.rb
CHANGED
@@ -7,6 +7,7 @@ class Lambchop::Cat
|
|
7
7
|
@function_name = function_name
|
8
8
|
@invoke_args = invoke_args
|
9
9
|
@client = options[:client] || Aws::Lambda::Client.new
|
10
|
+
@out = options[:out] || $stdout
|
10
11
|
@options = options
|
11
12
|
end
|
12
13
|
|
@@ -17,9 +18,33 @@ class Lambchop::Cat
|
|
17
18
|
invoke_args = invoke_args.read
|
18
19
|
end
|
19
20
|
|
20
|
-
@client.
|
21
|
+
resp = @client.invoke(
|
21
22
|
:function_name => @function_name,
|
22
|
-
:
|
23
|
+
:payload => invoke_args,
|
24
|
+
:invocation_type => Lambchop::Utils.camelize(@options[:invocation_type] || :request_response),
|
25
|
+
:log_type => Lambchop::Utils.camelize(@options[:log_type] || :none)
|
23
26
|
)
|
27
|
+
|
28
|
+
out = {
|
29
|
+
'status_code' => resp[:status_code],
|
30
|
+
'function_error' => resp[:function_error],
|
31
|
+
'payload' => nil
|
32
|
+
}
|
33
|
+
|
34
|
+
log_result = resp[:log_result]
|
35
|
+
payload = resp[:payload]
|
36
|
+
|
37
|
+
if log_result
|
38
|
+
log_result = Base64.strict_decode64(log_result)
|
39
|
+
log_result.gsub!("\t", ' ').strip!
|
40
|
+
def log_result.yaml_style() Psych::Nodes::Scalar::LITERAL end
|
41
|
+
out['log_result'] = log_result
|
42
|
+
end
|
43
|
+
|
44
|
+
if payload
|
45
|
+
out['payload'] = payload.string
|
46
|
+
end
|
47
|
+
|
48
|
+
@out.puts YAML.dump(out)
|
24
49
|
end
|
25
50
|
end
|
data/lib/lambchop/client.rb
CHANGED
@@ -23,10 +23,9 @@ class Lambchop::Client
|
|
23
23
|
config['function_name'] ||= File.basename(@path, '.js')
|
24
24
|
function_name = config['function_name']
|
25
25
|
|
26
|
-
config['mode'] ||= 'event'
|
27
26
|
config['runtime'] ||= 'nodejs'
|
28
27
|
|
29
|
-
|
28
|
+
create_or_update_function(config, src)
|
30
29
|
|
31
30
|
exit if @options[:detach]
|
32
31
|
|
@@ -38,23 +37,35 @@ class Lambchop::Client
|
|
38
37
|
|
39
38
|
private
|
40
39
|
|
41
|
-
def
|
40
|
+
def create_or_update_function(config, src)
|
42
41
|
params = {}
|
43
42
|
config.each {|k, v| params[k.to_sym] = v }
|
44
43
|
buf, node_modules = zip_source(src)
|
45
|
-
params[:function_zip] = buf.string
|
46
44
|
|
47
|
-
|
45
|
+
begin
|
46
|
+
params[:code] = {:zip_file => buf.string}
|
47
|
+
resp = @client.create_function(params)
|
48
|
+
rescue Aws::Lambda::Errors::ResourceConflictException => e
|
49
|
+
if e.message =~ /\AFunction already exist:/
|
50
|
+
params = {
|
51
|
+
:function_name => config['function_name'],
|
52
|
+
:zip_file => buf.string
|
53
|
+
}
|
54
|
+
|
55
|
+
resp = @client.update_function_code(params)
|
56
|
+
else
|
57
|
+
raise e
|
58
|
+
end
|
59
|
+
end
|
48
60
|
resp_h = {}
|
49
61
|
|
50
62
|
[
|
51
63
|
:function_name,
|
52
64
|
:function_arn,
|
53
|
-
:configuration_id,
|
54
65
|
:runtime,
|
55
66
|
:role,
|
56
67
|
:handler,
|
57
|
-
:
|
68
|
+
:code_size,
|
58
69
|
:description,
|
59
70
|
:timeout,
|
60
71
|
:memory_size,
|
data/lib/lambchop/diff.rb
CHANGED
@@ -21,7 +21,7 @@ class Lambchop::Diff
|
|
21
21
|
file = Lambchop::Utils.remove_shebang(file)
|
22
22
|
config, file = Lambchop::Utils.parse_magic_comment(file)
|
23
23
|
|
24
|
-
page = @client.get_function(:function_name => @function_name)
|
24
|
+
page = @client.get_function(:function_name => @function_name)
|
25
25
|
|
26
26
|
Lambchop::Utils.open_source(page.code.location) do |name, func|
|
27
27
|
diff = Diffy::Diff.new(func, file, :include_diff_info => true).to_s
|
data/lib/lambchop/dump.rb
CHANGED
@@ -11,7 +11,7 @@ class Lambchop::Dump
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def dump
|
14
|
-
page = @client.get_function(:function_name => @function_name)
|
14
|
+
page = @client.get_function(:function_name => @function_name)
|
15
15
|
puts_shebang
|
16
16
|
puts_magic_comment(page.configuration)
|
17
17
|
puts_source(page.code.location)
|
@@ -29,7 +29,6 @@ class Lambchop::Dump
|
|
29
29
|
runtime
|
30
30
|
role
|
31
31
|
handler
|
32
|
-
mode
|
33
32
|
description
|
34
33
|
timeout
|
35
34
|
memory_size
|
data/lib/lambchop/utils.rb
CHANGED
data/lib/lambchop/version.rb
CHANGED
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lambchop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: '2.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubyzip
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: diffy
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: It is a tool that invoke AWS Lambda function from the local machine as
|
@@ -93,7 +93,7 @@ executables:
|
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
-
-
|
96
|
+
- .gitignore
|
97
97
|
- Gemfile
|
98
98
|
- LICENSE.txt
|
99
99
|
- README.md
|
@@ -123,17 +123,17 @@ require_paths:
|
|
123
123
|
- lib
|
124
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
|
-
- -
|
126
|
+
- - '>='
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.0.14
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: It is a tool that invoke AWS Lambda function from the local machine as a
|