dpl 1.8.30.travis.1843.3 → 1.8.30.travis.1849.3
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 +1 -0
- data/lib/dpl/provider/lambda.rb +65 -25
- data/spec/provider/lambda_spec.rb +54 -15
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53f98382ab9c2fd449cf66a1673e1b7a3e502191
|
|
4
|
+
data.tar.gz: 60dc13bf847cf6d804be7affbb1e11d7dcda4c4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0fe508ade4e79f2ea574ed58cbd915c61d51c323e901f8ee8d7b8e5290470613230e4d19cbf9502f8e2f9e5394138e1b21ba6926ca69f5b1ccca0b2ff7d9cf3c
|
|
7
|
+
data.tar.gz: 62c45debd3a88b8502c0cafb13a0a57e58f6398350f862334de3e3176faf5162cdfd9412da91957accb1a2183ae331c0f4ebdbb571de3feb3a087a8bf3db9f6c
|
data/README.md
CHANGED
|
@@ -707,6 +707,7 @@ c. Update your `before_deploy` step in `.travis.yml` to update the `known_hosts`
|
|
|
707
707
|
* **timeout**: Optional. The function execution time at which Lambda should terminate the function. Defaults to 3 (seconds).
|
|
708
708
|
* **memory_size**: Optional. The amount of memory in MB to allocate to this Lambda. Defaults to 128.
|
|
709
709
|
* **runtime**: Optional. The Lambda runtime to use. Defaults to `node`.
|
|
710
|
+
* **publish**: If `true`, a [new version](http://docs.aws.amazon.com/lambda/latest/dg/versioning-intro.html#versioning-intro-publish-version) of the Lambda function will be created instead of replacing the code of the existing one.
|
|
710
711
|
|
|
711
712
|
#### Examples:
|
|
712
713
|
|
data/lib/dpl/provider/lambda.rb
CHANGED
|
@@ -9,7 +9,7 @@ module DPL
|
|
|
9
9
|
requires 'rubyzip', load: 'zip'
|
|
10
10
|
|
|
11
11
|
def lambda
|
|
12
|
-
@lambda ||= ::Aws::
|
|
12
|
+
@lambda ||= ::Aws::Lambda::Client.new(lambda_options)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def lambda_options
|
|
@@ -20,27 +20,67 @@ module DPL
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def push_app
|
|
23
|
-
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
|
|
24
|
+
# The original LambdaPreview client supported create/update in one call
|
|
25
|
+
# To keep compatibility we try to fetch the function and then decide
|
|
26
|
+
# whether to update the code or create a new function
|
|
27
|
+
|
|
28
|
+
function_name = options[:name] || option(:function_name)
|
|
29
|
+
|
|
30
|
+
response = lambda.list_functions
|
|
31
|
+
|
|
32
|
+
if response.functions.any? { |function| function.function_name == function_name }
|
|
33
|
+
|
|
34
|
+
log "Function #{function_name} already exists, updating."
|
|
35
|
+
|
|
36
|
+
# Options defined at
|
|
37
|
+
# https://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Client.html#update_function_configuration-instance_method
|
|
38
|
+
response = lambda.update_function_configuration({
|
|
39
|
+
function_name: function_name,
|
|
40
|
+
description: options[:description] || default_description,
|
|
41
|
+
timeout: options[:timeout] || default_timeout,
|
|
42
|
+
memory_size: options[:memory_size] || default_memory_size,
|
|
43
|
+
role: option(:role),
|
|
44
|
+
handler: handler,
|
|
45
|
+
runtime: options[:runtime] || default_runtime,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
log "Updated configuration of function: #{response.function_name}."
|
|
50
|
+
|
|
51
|
+
# Options defined at
|
|
52
|
+
# https://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Client.html#update_function_code-instance_method
|
|
53
|
+
response = lambda.update_function_code({
|
|
54
|
+
function_name: options[:name] || option(:function_name),
|
|
55
|
+
zip_file: function_zip,
|
|
56
|
+
publish: publish,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
log "Updated code of function: #{response.function_name}."
|
|
60
|
+
else
|
|
61
|
+
# Options defined at
|
|
62
|
+
# https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html
|
|
63
|
+
response = lambda.create_function({
|
|
64
|
+
function_name: options[:name] || option(:function_name),
|
|
65
|
+
description: options[:description] || default_description,
|
|
66
|
+
timeout: options[:timeout] || default_timeout,
|
|
67
|
+
memory_size: options[:memory_size] || default_memory_size,
|
|
68
|
+
role: option(:role),
|
|
69
|
+
handler: handler,
|
|
70
|
+
code: {
|
|
71
|
+
zip_file: function_zip,
|
|
72
|
+
},
|
|
73
|
+
runtime: options[:runtime] || default_runtime,
|
|
74
|
+
publish: publish,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
log "Created lambda: #{response.function_name}."
|
|
78
|
+
end
|
|
79
|
+
rescue ::Aws::Lambda::Errors::ServiceException => exception
|
|
40
80
|
error(exception.message)
|
|
41
|
-
rescue ::Aws::
|
|
81
|
+
rescue ::Aws::Lambda::Errors::InvalidParameterValueException => exception
|
|
42
82
|
error(exception.message)
|
|
43
|
-
rescue ::Aws::
|
|
83
|
+
rescue ::Aws::Lambda::Errors::ResourceNotFoundException => exception
|
|
44
84
|
error(exception.message)
|
|
45
85
|
end
|
|
46
86
|
|
|
@@ -111,10 +151,6 @@ module DPL
|
|
|
111
151
|
'nodejs'
|
|
112
152
|
end
|
|
113
153
|
|
|
114
|
-
def default_mode
|
|
115
|
-
'event'
|
|
116
|
-
end
|
|
117
|
-
|
|
118
154
|
def default_timeout
|
|
119
155
|
3 # seconds
|
|
120
156
|
end
|
|
@@ -123,7 +159,7 @@ module DPL
|
|
|
123
159
|
"Deploy build #{context.env['TRAVIS_BUILD_NUMBER']} to AWS Lambda via Travis CI"
|
|
124
160
|
end
|
|
125
161
|
|
|
126
|
-
def
|
|
162
|
+
def default_memory_size
|
|
127
163
|
128
|
|
128
164
|
end
|
|
129
165
|
|
|
@@ -131,6 +167,10 @@ module DPL
|
|
|
131
167
|
'index'
|
|
132
168
|
end
|
|
133
169
|
|
|
170
|
+
def publish
|
|
171
|
+
!!options[:publish]
|
|
172
|
+
end
|
|
173
|
+
|
|
134
174
|
def random_chars(count=8)
|
|
135
175
|
(36**(count-1) + rand(36**count - 36**(count-1))).to_s(36)
|
|
136
176
|
end
|
|
@@ -53,7 +53,7 @@ describe DPL::Provider::Lambda do
|
|
|
53
53
|
|
|
54
54
|
describe '#lambda' do
|
|
55
55
|
example do
|
|
56
|
-
expect(Aws::
|
|
56
|
+
expect(Aws::Lambda::Client).to receive(:new).with(client_options).once
|
|
57
57
|
provider.lambda
|
|
58
58
|
end
|
|
59
59
|
end
|
|
@@ -66,6 +66,16 @@ describe DPL::Provider::Lambda do
|
|
|
66
66
|
handler_name: 'handler'
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
list_functions_response = {
|
|
70
|
+
functions: [
|
|
71
|
+
{ function_name: 'test-function' }
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
empty_list_functions_response = {
|
|
76
|
+
functions: [ ]
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
example_response = {
|
|
70
80
|
function_name: 'test-function',
|
|
71
81
|
role: 'some-role',
|
|
@@ -77,20 +87,37 @@ describe DPL::Provider::Lambda do
|
|
|
77
87
|
provider.stub(:options) { old_options.merge(lambda_options) }
|
|
78
88
|
end
|
|
79
89
|
|
|
80
|
-
context '
|
|
90
|
+
context 'by creating a new function' do
|
|
91
|
+
before do
|
|
92
|
+
provider.lambda.stub_responses(:list_functions, empty_list_functions_response)
|
|
93
|
+
provider.lambda.stub_responses(:create_function, example_response)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
example do
|
|
97
|
+
expect(provider).to receive(:log).with(/Created lambda: #{lambda_options[:function_name]}\./)
|
|
98
|
+
provider.push_app
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context 'by updating an existing function' do
|
|
81
103
|
before do
|
|
82
|
-
provider.lambda.stub_responses(:
|
|
104
|
+
provider.lambda.stub_responses(:list_functions, list_functions_response)
|
|
105
|
+
provider.lambda.stub_responses(:update_function_configuration, example_response)
|
|
106
|
+
provider.lambda.stub_responses(:update_function_code, example_response)
|
|
83
107
|
end
|
|
84
108
|
|
|
85
109
|
example do
|
|
86
|
-
expect(provider).to receive(:log).with(/
|
|
110
|
+
expect(provider).to receive(:log).with(/Function #{lambda_options[:function_name]} already exists, updating\./)
|
|
111
|
+
expect(provider).to receive(:log).with(/Updated configuration of function: #{lambda_options[:function_name]}\./)
|
|
112
|
+
expect(provider).to receive(:log).with(/Updated code of function: #{lambda_options[:function_name]}\./)
|
|
87
113
|
provider.push_app
|
|
88
114
|
end
|
|
89
115
|
end
|
|
90
116
|
|
|
91
117
|
context 'with a ServiceException response' do
|
|
92
118
|
before do
|
|
93
|
-
provider.lambda.stub_responses(:
|
|
119
|
+
provider.lambda.stub_responses(:list_functions, 'ResourceNotFoundException')
|
|
120
|
+
provider.lambda.stub_responses(:create_function, 'ServiceException')
|
|
94
121
|
end
|
|
95
122
|
|
|
96
123
|
example do
|
|
@@ -101,7 +128,7 @@ describe DPL::Provider::Lambda do
|
|
|
101
128
|
|
|
102
129
|
context 'with a InvalidParameterValueException response' do
|
|
103
130
|
before do
|
|
104
|
-
provider.lambda.stub_responses(:
|
|
131
|
+
provider.lambda.stub_responses(:list_functions, 'InvalidParameterValueException')
|
|
105
132
|
end
|
|
106
133
|
|
|
107
134
|
example do
|
|
@@ -112,7 +139,8 @@ describe DPL::Provider::Lambda do
|
|
|
112
139
|
|
|
113
140
|
context 'with a ResourceNotFoundException response' do
|
|
114
141
|
before do
|
|
115
|
-
provider.lambda.stub_responses(:
|
|
142
|
+
provider.lambda.stub_responses(:list_functions, 'ResourceNotFoundException')
|
|
143
|
+
provider.lambda.stub_responses(:create_function, 'ResourceNotFoundException')
|
|
116
144
|
end
|
|
117
145
|
|
|
118
146
|
example do
|
|
@@ -320,12 +348,6 @@ describe DPL::Provider::Lambda do
|
|
|
320
348
|
end
|
|
321
349
|
end
|
|
322
350
|
|
|
323
|
-
describe '#default_mode' do
|
|
324
|
-
example do
|
|
325
|
-
expect(provider.default_mode).to eq('event')
|
|
326
|
-
end
|
|
327
|
-
end
|
|
328
|
-
|
|
329
351
|
describe '#default_timeout' do
|
|
330
352
|
example do
|
|
331
353
|
expect(provider.default_timeout).to eq(3)
|
|
@@ -348,9 +370,26 @@ describe DPL::Provider::Lambda do
|
|
|
348
370
|
end
|
|
349
371
|
end
|
|
350
372
|
|
|
351
|
-
describe '#
|
|
373
|
+
describe '#default_memory_size' do
|
|
352
374
|
example do
|
|
353
|
-
expect(provider.
|
|
375
|
+
expect(provider.default_memory_size).to eq(128)
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
describe '#publish' do
|
|
380
|
+
context 'is default turned off' do
|
|
381
|
+
example do
|
|
382
|
+
expect(provider.publish).to eq(false)
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
context 'can be turned on' do
|
|
386
|
+
before do
|
|
387
|
+
expect(provider.options).to receive(:[]).with(:publish).and_return(true)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
example do
|
|
391
|
+
expect(provider.publish).to eq(true)
|
|
392
|
+
end
|
|
354
393
|
end
|
|
355
394
|
end
|
|
356
395
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dpl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.8.30.travis.
|
|
4
|
+
version: 1.8.30.travis.1849.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Konstantin Haase
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|