dpl 1.8.43.travis.2280.5 → 1.8.43.travis.2283.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 336c29967990e23fe9b833a5f85ab135a4f3aac6
4
- data.tar.gz: a3d36f23459eb95b83dfad5a9657eaa512a4cdc4
3
+ metadata.gz: ed76725b0159655c032234e61b2b7d2ed74e80d2
4
+ data.tar.gz: 1994bde72ede5e6d8366342db093268b1715e321
5
5
  SHA512:
6
- metadata.gz: d5d8b4c209fcd879736f57adcab464adb56be6f8a683e08123aede9494874b580f1ed1a5b5e1f984cfffe3e7eb561487a672877e4366842c9c7b2e93f05a10f1
7
- data.tar.gz: 0ab12f8b19c674387b4e8140048b5de4dc4751bff674f8411c30607eea7f537f0f4454d989b02948cdb3e445ba502dbc7cf620421b650b5aee565f357938363c
6
+ metadata.gz: 189c488bc73a7ad414f662815be6443ca20240a2add040b9f8f1cc629a31942cc10d3de991b66c642a778be29febb7266c2cfe7296216755b76844cf7bda4e02
7
+ data.tar.gz: ca43bdcc921666271590c89adf03128749af2a6e9b4e7a1b5d16f30e717802d328dae62ca23cf67c86e37a319055f5cdf10abe8544bc35b572c0ecdf907865e0
data/Gemfile CHANGED
@@ -33,16 +33,16 @@ group :rubygems do
33
33
  end
34
34
 
35
35
  group :sss do
36
- gem 'aws-sdk', '~> 2.6.32', '< 3.0'
36
+ gem 'aws-sdk', '~> 2.10.39', '< 3.0'
37
37
  gem 'mime-types'
38
38
  end
39
39
 
40
40
  group :code_deploy do
41
- gem 'aws-sdk', '~> 2.6.32', '< 3.0'
41
+ gem 'aws-sdk', '~> 2.10.39', '< 3.0'
42
42
  end
43
43
 
44
44
  group :lambda do
45
- gem 'aws-sdk', '~> 2.6.32', '< 3.0'
45
+ gem 'aws-sdk', '~> 2.10.39', '< 3.0'
46
46
  gem 'rubyzip', '~> 1.1'
47
47
  end
48
48
 
@@ -63,7 +63,7 @@ group :gcs do
63
63
  end
64
64
 
65
65
  group :elastic_beanstalk do
66
- gem 'aws-sdk', '~> 2.6.32', '< 3.0'
66
+ gem 'aws-sdk', '~> 2.10.39', '< 3.0'
67
67
  gem 'rubyzip', '~> 1.1'
68
68
  end
69
69
 
@@ -96,5 +96,5 @@ group :deis do
96
96
  end
97
97
 
98
98
  group :opsworks do
99
- gem 'aws-sdk', '~> 2.6.32', '< 3.0'
99
+ gem 'aws-sdk', '~> 2.10.39', '< 3.0'
100
100
  end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Dpl [![Build Status](https://travis-ci.org/travis-ci/dpl.svg?branch=master)](https://travis-ci.org/travis-ci/dpl) [![Code Climate](https://codeclimate.com/github/travis-ci/dpl.png)](https://codeclimate.com/github/travis-ci/dpl) [![Gem Version](https://badge.fury.io/rb/dpl.png)](http://badge.fury.io/rb/dpl) [![Coverage Status](https://coveralls.io/repos/travis-ci/dpl/badge.svg?branch=master&service=github)](https://coveralls.io/github/travis-ci/dpl?branch=master)
2
2
 
3
- ## Writing and Testing a New Deployment Provider and new functionalities
3
+ ## Writing and Testing a New Deployment Provider and new functionality
4
4
 
5
5
  See [TESTING.md](TESTING.md).
6
6
 
@@ -714,6 +714,17 @@ For accounts using two factor authentication, you have to use an oauth token as
714
714
  * **memory_size**: Optional. The amount of memory in MB to allocate to this Lambda. Defaults to 128.
715
715
  * **runtime**: Optional. The Lambda runtime to use. Defaults to `node`.
716
716
  * **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.
717
+ * **subnet_ids**: Optional. List of subnet IDs to be added to the function. Needs the `ec2:DescribeSubnets` and `ec2:DescribeVpcs` permission for the user of the access/secret key to work.
718
+ * **security_group_ids**: Optional. List of security group IDs to be added to the function. Needs the `ec2:DescribeSecurityGroups` and `ec2:DescribeVpcs` permission for the user of the access/secret key to work.
719
+ * **dead_letter_arn**: Optional. ARN to an SNS or SQS resource used for the dead letter queue. [More about DLQs here](https://docs.aws.amazon
720
+ .com/lambda/latest/dg/dlq.html).
721
+ * **tracing_mode**: Optional. "Active" or "PassThrough" only. Default is "PassThrough". Needs the `xray:PutTraceSegments` and `xray:PutTelemetryRecords` on the role for this to work. [More on
722
+ Active Tracing here](https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html).
723
+ * **environment_variables**: Optional. List of Environment Variables to add to the function, needs to be in the format of `KEY=VALUE`. Can be encrypted for added security.
724
+ * **kms_key_arn**: Optional. KMS key ARN to use to encrypt `environment_variables`.
725
+ * **function_tags**: Optional. List of tags to add to the function, needs to be in the format of `KEY=VALUE`. Can be encrypted for added security.
726
+
727
+ For a list of all [permissions for Lambda, please refer to the documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-api-permissions-ref.html).
717
728
 
718
729
  #### Examples:
719
730
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'rspec', '~> 3.0.0'
20
20
  s.add_development_dependency 'rspec-its'
21
21
  s.add_development_dependency 'rake'
22
- s.add_development_dependency 'json', '1.8.1'
22
+ s.add_development_dependency 'json', '1.8.3'
23
23
  s.add_development_dependency 'tins', '~> 1.6.0', '>= 1.6.0'
24
24
  s.add_development_dependency 'coveralls'
25
25
 
@@ -14,8 +14,8 @@ module DPL
14
14
 
15
15
  def lambda_options
16
16
  {
17
- region: options[:region] || 'us-east-1',
18
- credentials: ::Aws::Credentials.new(option(:access_key_id), option(:secret_access_key))
17
+ region: options[:region] || 'us-east-1',
18
+ credentials: ::Aws::Credentials.new(option(:access_key_id), option(:secret_access_key))
19
19
  }
20
20
  end
21
21
 
@@ -26,53 +26,71 @@ module DPL
26
26
  # whether to update the code or create a new function
27
27
 
28
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 }
29
+
30
+ begin
31
+ response = lambda.get_function({function_name: function_name})
33
32
 
34
33
  log "Function #{function_name} already exists, updating."
35
34
 
36
35
  # Options defined at
37
36
  # https://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Client.html#update_function_configuration-instance_method
38
37
  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
-
38
+ function_name: function_name,
39
+ description: options[:description] || default_description,
40
+ timeout: options[:timeout] || default_timeout,
41
+ memory_size: options[:memory_size] || default_memory_size,
42
+ role: option(:role),
43
+ handler: handler,
44
+ runtime: options[:runtime] || default_runtime,
45
+ vpc_config: vpc_config,
46
+ environment: environment_variables,
47
+ dead_letter_config: dead_letter_arn,
48
+ kms_key_arn: options[:kms_key_arn] || default_kms_key_arn,
49
+ tracing_config: tracing_mode
50
+ })
48
51
 
49
52
  log "Updated configuration of function: #{response.function_name}."
50
53
 
54
+ if function_tags
55
+ log "Add tags to function #{response.function_name}."
56
+ response = lambda.tag_resource({
57
+ resource: response.function_arn,
58
+ tags: function_tags
59
+ })
60
+ end
61
+
51
62
  # Options defined at
52
63
  # https://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Client.html#update_function_code-instance_method
53
64
  response = lambda.update_function_code({
54
- function_name: options[:name] || option(:function_name),
55
- zip_file: function_zip,
56
- publish: publish,
57
- })
65
+ function_name: options[:name] || option(:function_name),
66
+ zip_file: function_zip,
67
+ publish: publish
68
+ })
58
69
 
59
70
  log "Updated code of function: #{response.function_name}."
60
- else
71
+ rescue ::Aws::Lambda::Errors::ResourceNotFoundException
72
+ log "Function #{function_name} does not exist, creating."
61
73
  # Options defined at
62
74
  # https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html
63
75
  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
+ function_name: options[:name] || option(:function_name),
77
+ description: options[:description] || default_description,
78
+ timeout: options[:timeout] || default_timeout,
79
+ memory_size: options[:memory_size] || default_memory_size,
80
+ role: option(:role),
81
+ handler: handler,
82
+ code: {
83
+ zip_file: function_zip,
84
+ },
85
+ runtime: options[:runtime] || default_runtime,
86
+ publish: publish,
87
+ vpc_config: vpc_config,
88
+ environment: environment_variables,
89
+ dead_letter_config: dead_letter_arn,
90
+ kms_key_arn: options[:kms_key_arn] || default_kms_key_arn,
91
+ tracing_config: tracing_mode,
92
+ tags: function_tags
93
+ })
76
94
 
77
95
  log "Created lambda: #{response.function_name}."
78
96
  end
@@ -147,6 +165,30 @@ module DPL
147
165
  @output_file_path ||= '/tmp/' + random_chars(8) + '-lambda.zip'
148
166
  end
149
167
 
168
+ def vpc_config
169
+ options[:subnet_ids] && options[:security_group_ids] ? { :subnet_ids => Array(options[:subnet_ids]), :security_group_ids => Array(options[:security_group_ids]) } : nil
170
+ end
171
+
172
+ def environment_variables
173
+ options[:environment_variables] ? { :variables => split_string_array_to_hash(options[:environment_variables]) } : nil
174
+ end
175
+
176
+ def dead_letter_arn
177
+ options[:dead_letter_arn] ? { :target_arn => options[:dead_letter_arn]} : nil
178
+ end
179
+
180
+ def tracing_mode
181
+ options[:tracing_mode] ? { :mode => options[:tracing_mode]} : nil
182
+ end
183
+
184
+ def default_kms_key_arn
185
+ nil
186
+ end
187
+
188
+ def function_tags
189
+ options[:function_tags] ? split_string_array_to_hash(options[:function_tags]) : nil
190
+ end
191
+
150
192
  def default_runtime
151
193
  'nodejs'
152
194
  end
@@ -171,6 +213,15 @@ module DPL
171
213
  !!options[:publish]
172
214
  end
173
215
 
216
+ def split_string_array_to_hash(arr, delimiter="=")
217
+ variables = {}
218
+ Array(arr).map do |val|
219
+ keyval = val.split(delimiter)
220
+ variables[keyval[0]] = keyval[1]
221
+ end
222
+ variables
223
+ end
224
+
174
225
  def random_chars(count=8)
175
226
  (36**(count-1) + rand(36**count - 36**(count-1))).to_s(36)
176
227
  end
@@ -66,18 +66,19 @@ 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: [ ]
69
+ example_get_function_response = {
70
+ code: {
71
+ location: 'location',
72
+ repository_type: 's3',
73
+ },
74
+ configuration: {
75
+ function_name: 'test-function'
76
+ }
77
77
  }
78
78
 
79
79
  example_response = {
80
80
  function_name: 'test-function',
81
+ function_arn: 'arn:lambda:region:account-id:function:test-function',
81
82
  role: 'some-role',
82
83
  handler: 'index.handler'
83
84
  }
@@ -89,11 +90,13 @@ describe DPL::Provider::Lambda do
89
90
 
90
91
  context 'by creating a new function' do
91
92
  before do
92
- provider.lambda.stub_responses(:list_functions, empty_list_functions_response)
93
+ provider.lambda.stub_responses(:get_function, 'ResourceNotFoundException')
93
94
  provider.lambda.stub_responses(:create_function, example_response)
94
95
  end
95
96
 
96
97
  example do
98
+
99
+ expect(provider).to receive(:log).with(/Function #{lambda_options[:function_name]} does not exist, creating\./)
97
100
  expect(provider).to receive(:log).with(/Created lambda: #{lambda_options[:function_name]}\./)
98
101
  provider.push_app
99
102
  end
@@ -101,14 +104,32 @@ describe DPL::Provider::Lambda do
101
104
 
102
105
  context 'by updating an existing function' do
103
106
  before do
104
- provider.lambda.stub_responses(:list_functions, list_functions_response)
107
+ provider.lambda.stub_responses(:get_function, example_get_function_response)
108
+ provider.lambda.stub_responses(:update_function_configuration, example_response)
109
+ provider.lambda.stub_responses(:update_function_code, example_response)
110
+ end
111
+
112
+ example do
113
+ expect(provider).to receive(:log).with(/Function #{lambda_options[:function_name]} already exists, updating\./)
114
+ expect(provider).to receive(:log).with(/Updated configuration of function: #{lambda_options[:function_name]}\./)
115
+ expect(provider).to receive(:log).with(/Updated code of function: #{lambda_options[:function_name]}\./)
116
+ provider.push_app
117
+ end
118
+ end
119
+
120
+ context 'by updating an existing function with new tags' do
121
+ before do
122
+ lambda_options[:function_tags] = [ 'TAG_KEY=some-value' ]
123
+ provider.lambda.stub_responses(:get_function, example_get_function_response)
105
124
  provider.lambda.stub_responses(:update_function_configuration, example_response)
125
+ provider.lambda.stub_responses(:tag_resource)
106
126
  provider.lambda.stub_responses(:update_function_code, example_response)
107
127
  end
108
128
 
109
129
  example do
110
130
  expect(provider).to receive(:log).with(/Function #{lambda_options[:function_name]} already exists, updating\./)
111
131
  expect(provider).to receive(:log).with(/Updated configuration of function: #{lambda_options[:function_name]}\./)
132
+ expect(provider).to receive(:log).with(/Add tags to function #{lambda_options[:function_name]}\./)
112
133
  expect(provider).to receive(:log).with(/Updated code of function: #{lambda_options[:function_name]}\./)
113
134
  provider.push_app
114
135
  end
@@ -116,7 +137,7 @@ describe DPL::Provider::Lambda do
116
137
 
117
138
  context 'with a ServiceException response' do
118
139
  before do
119
- provider.lambda.stub_responses(:list_functions, 'ResourceNotFoundException')
140
+ provider.lambda.stub_responses(:get_function, 'ResourceNotFoundException')
120
141
  provider.lambda.stub_responses(:create_function, 'ServiceException')
121
142
  end
122
143
 
@@ -128,7 +149,7 @@ describe DPL::Provider::Lambda do
128
149
 
129
150
  context 'with a InvalidParameterValueException response' do
130
151
  before do
131
- provider.lambda.stub_responses(:list_functions, 'InvalidParameterValueException')
152
+ provider.lambda.stub_responses(:get_function, 'InvalidParameterValueException')
132
153
  end
133
154
 
134
155
  example do
@@ -139,7 +160,7 @@ describe DPL::Provider::Lambda do
139
160
 
140
161
  context 'with a ResourceNotFoundException response' do
141
162
  before do
142
- provider.lambda.stub_responses(:list_functions, 'ResourceNotFoundException')
163
+ provider.lambda.stub_responses(:get_function, 'ResourceNotFoundException')
143
164
  provider.lambda.stub_responses(:create_function, 'ResourceNotFoundException')
144
165
  end
145
166
 
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.43.travis.2280.5
4
+ version: 1.8.43.travis.2283.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.8.1
61
+ version: 1.8.3
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
- version: 1.8.1
68
+ version: 1.8.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tins
71
71
  requirement: !ruby/object:Gem::Requirement