cloudformation-tool 0.6.5 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bce6870ac6673790b3c415e13943639a5af5c4f
4
- data.tar.gz: cafabf00b0990298d934a0effe4a42bcc6f57ec9
3
+ metadata.gz: da07cd386a792f6dee84862962bd5f3bcd9e243a
4
+ data.tar.gz: d46054b28aa9bbfba9e9f88d22bd93a6b2caeb06
5
5
  SHA512:
6
- metadata.gz: f95dd5e742825fa0eba2b602e5f84c49a1a80d7018aa22d8515c6e15133eea16db0c00a5cceae6d32eabd081806dc66d0019aff00420e77ae60bcc59559d0808
7
- data.tar.gz: 74838f921a39b438ea578c1ce61394604e4643c36ad0a894e3e7b3ac3dc6a847913d326c451910e0468e67ebc133186635a5c9a10ac885ec4a8a071162dc0172
6
+ metadata.gz: 817e208ec95ef44733bac7ec1d5967d9df51ceadde2b9f8317a4720d759fc4d0dced12e7e133816b2c8896664b7b8f1bf2ddbceb59c60e00dc5f92169c55ab28
7
+ data.tar.gz: 560890e77e1060c1fa234c633699566ee2885e143f833abd4409d89ea6216352b4f33f6dfae9333b74eb94dfdf8d9f131b9d0e052f33d957780b2fb7343963e3
data/README.md CHANGED
@@ -188,11 +188,12 @@ write_directory:
188
188
  ### Loading Lambda code
189
189
 
190
190
  When specifying the `Code` property of a `AWS::Lambda::Function` resource, instead of
191
- specifying the S3 bucket and object key, the field `URL` may be used to specify an HTTP URL
192
- from which the code is to be uploaded to AWS Lambda. The tool will download the code file from
193
- the specified URL, upload it to S3 and specify the correct S3 location for CloudFormation.
194
-
195
- In the future we plan to add support for specifying `File` to upload from a local file.
191
+ specifying the S3 bucket and object key, either of the following fields may be used:
192
+ - The field `URL` may be used to specify an HTTP URL from which the code is to be uploaded to AWS Lambda. The tool
193
+ will download the code file from the specified URL, upload it to S3 and specify the correct S3 location for
194
+ CloudFormation.
195
+ - The field `Path` may be used to specify a local file or directory containing the code to be uploaded.
196
+ If the path specifies a directory, it will be compressed as a Zip file.
196
197
 
197
198
  #### Example:
198
199
 
@@ -163,11 +163,18 @@ module CloudFormationTool
163
163
  # Support Lambda Code from arbitrary URLs
164
164
  url = resolveVal(val["URL"])
165
165
  if url.is_a? String # resolving works
166
- LambdaCode.new(url).to_cloudformation
166
+ LambdaCode.new(url: url).to_cloudformation
167
167
  else # resolving didn't work - we probably don't have parameters
168
168
  # push it upstream and hope a parent template can resolve it
169
169
  val
170
170
  end
171
+ elsif (key == "Code") and (val["Path"])
172
+ path = resolveVal(val["Path"])
173
+ if path.is_a? String # resolving works
174
+ LambdaCode.new(path: "#{@basedir}/#{path}").to_cloudformation
175
+ else # resolving didn't work - we probably don't have parameters
176
+ val
177
+ end
171
178
  else
172
179
  load_files(val)
173
180
  end
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'zip'
2
3
 
3
4
  module CloudFormationTool
4
5
  class CloudFormation
@@ -6,15 +7,40 @@ module CloudFormationTool
6
7
  class LambdaCode
7
8
  include Storable
8
9
 
9
- def initialize(url)
10
- log "Downloading Lambda code from #{url}"
11
- res = fetch(url)
12
-
13
- @s3_url = URI(upload(make_filename(url.split('.').last), res.body, mime_type: res['content-type'], gzip: false))
10
+ def initialize(url: nil, path: nil)
11
+ log "Downloading Lambda code from #{url}#{path}"
12
+ case url
13
+ when nil
14
+ @s3_url = if File.directory?(path)
15
+ URI(upload(make_filename(path.split('/').last), fetch_from_folder(path), mime_type: 'application/zip', gzip: false))
16
+ else
17
+ URI(upload(make_filename(path.split('/').last), File.open(path, "rb").read, gzip: false))
18
+ end
19
+ else
20
+ res = fetch_from_url(url)
21
+ @s3_url = URI(upload(make_filename(url.split('.').last), res.body, mime_type: res['content-type'], gzip: false))
22
+ end
14
23
  log "uploaded Lambda function to #{@s3_url}"
15
24
  end
16
25
 
17
- def fetch(uri_str, limit = 10)
26
+ def fetch_from_folder(path_str)
27
+ begin
28
+ temp_file = Tempfile.new("#{path_str.split('/').last}.zip")
29
+ Zip::ZipOutputStream.open(temp_file) { |zos| }
30
+ Zip::ZipFile.open(temp_file.path, Zip::ZipFile::CREATE) do |zipfile|
31
+ Dir[File.join(path_str, '*')].each do |file|
32
+ zipfile.add(file.sub("#{path_str}/", ''), file)
33
+ end
34
+ end
35
+ zip_data = File.read(temp_file.path)
36
+ ensure
37
+ temp_file.close
38
+ temp_file.unlink
39
+ end
40
+ zip_data
41
+ end
42
+
43
+ def fetch_from_url(uri_str, limit = 10)
18
44
  raise ArgumentError, 'too many HTTP redirects' if limit == 0
19
45
  response = Net::HTTP.get_response(URI(uri_str))
20
46
  case response
@@ -1,3 +1,3 @@
1
1
  module CloudFormationTool
2
- VERSION = '0.6.5'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Arbel
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
55
69
  description:
56
70
  email: oded.arbel@greenfieldtech.net
57
71
  executables:
@@ -103,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  version: '0'
104
118
  requirements: []
105
119
  rubyforge_project:
106
- rubygems_version: 2.6.13
120
+ rubygems_version: 2.6.14
107
121
  signing_key:
108
122
  specification_version: 4
109
123
  summary: A pre-compiler tool for CloudFormation YAML templates