lambda_wrap 0.26.0 → 0.26.6
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/lib/lambda_wrap/api_gateway_manager.rb +180 -180
- data/lib/lambda_wrap/dynamo_db_manager.rb +181 -176
- data/lib/lambda_wrap/lambda_manager.rb +208 -196
- data/lib/lambda_wrap/s3_bucket_manager.rb +5 -8
- data/lib/lambda_wrap/version.rb +3 -0
- data/lib/lambda_wrap/zip_file_generator.rb +67 -67
- data/lib/lambda_wrap.rb +5 -5
- metadata +9 -6
@@ -1,196 +1,208 @@
|
|
1
|
-
require 'aws-sdk'
|
2
|
-
|
3
|
-
module LambdaWrap
|
4
|
-
##
|
5
|
-
# The LambdaManager simplifies creating a package, publishing to S3, deploying a new version, & setting permissions.
|
6
|
-
#
|
7
|
-
# Note: The concept of an environment of the LambdaWrap gem matches an alias of AWS Lambda.
|
8
|
-
class LambdaManager
|
9
|
-
##
|
10
|
-
# The constructor does some basic setup
|
11
|
-
# * Validating basic AWS configuration
|
12
|
-
# * Creating the underlying client to interace with the AWS SDK
|
13
|
-
def initialize
|
14
|
-
# AWS lambda client
|
15
|
-
@client = Aws::Lambda::Client.new
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# Packages a set of files and node modules into a deployable package.
|
20
|
-
#
|
21
|
-
# *Arguments*
|
22
|
-
# [directory] A temporary directory to copy all related files before they are packages into a single zip file.
|
23
|
-
# [zipfile] A path where the deployable package, a zip file, should be stored.
|
24
|
-
# [input_filenames] A list of file names that contain the source code.
|
25
|
-
# [node_modules] A list of node modules that need to be included in the package.
|
26
|
-
def package(directory, zipfile, input_filenames, node_modules)
|
27
|
-
FileUtils.mkdir_p directory
|
28
|
-
FileUtils.mkdir_p File.join(directory, 'node_modules') unless node_modules.
|
29
|
-
|
30
|
-
input_filenames.each do |filename|
|
31
|
-
FileUtils.copy_file(File.join(filename), File.join(directory, File.basename(filename)))
|
32
|
-
end
|
33
|
-
|
34
|
-
node_modules.each do |dir|
|
35
|
-
FileUtils.cp_r(File.join('node_modules', dir), File.join(directory, 'node_modules'))
|
36
|
-
end
|
37
|
-
|
38
|
-
ZipFileGenerator.new(directory, zipfile).write
|
39
|
-
end
|
40
|
-
|
41
|
-
##
|
42
|
-
# Publishes a package to S3 so it can be deployed as a lambda function.
|
43
|
-
#
|
44
|
-
# *Arguments*
|
45
|
-
# [local_lambda_file] The location of the package that needs to be deployed.
|
46
|
-
# [bucket] The s3 bucket where the file needs to be uploaded to.
|
47
|
-
# [key] The S3 path (key) where the package should be stored.
|
48
|
-
def publish_lambda_to_s3(local_lambda_file, bucket, key)
|
49
|
-
# get s3 object
|
50
|
-
s3 = Aws::S3::Resource.new
|
51
|
-
obj = s3.bucket(bucket).object(key)
|
52
|
-
|
53
|
-
# upload
|
54
|
-
version_id = nil
|
55
|
-
File.open(local_lambda_file, 'rb') do |file|
|
56
|
-
version_id = obj.put(body: file).version_id
|
57
|
-
end
|
58
|
-
raise 'Upload to S3 failed' unless version_id
|
59
|
-
|
60
|
-
puts 'Uploaded object to S3 with version ' + version_id
|
61
|
-
version_id
|
62
|
-
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# Deploys a package that has been uploaded to S3.
|
66
|
-
#
|
67
|
-
# *Arguments*
|
68
|
-
# [bucket] The S3 bucket where the package can be retrieved from.
|
69
|
-
# [key] The S3 path (key) where the package can be retrieved from.
|
70
|
-
# [version_id] The version of the file on S3 to retrieve.
|
71
|
-
# [function_name] The name of the lambda function.
|
72
|
-
# [handler] The handler that should be executed for this lambda function.
|
73
|
-
# [lambda_role] The arn of the IAM role that should be used when executing the lambda function.
|
74
|
-
# [lambda_description] The description of the lambda function.
|
75
|
-
# [vpc_subnet_ids] A list of subnet ids for the lambda's VPC configuration. All subnets must be on the same VPC.
|
76
|
-
# [vpc_security_group_ids] A list of security group ids for the lambda's VPC configuration. All of the
|
77
|
-
# security_group_ids must be on the same VPC.
|
78
|
-
# [runtime] The runtime the code is written for.
|
79
|
-
# [timeout] The integer value of seconds until the lambda timesout. Minimum 1, Maximum 300
|
80
|
-
# [memory_size] The Memory/ProcessingPower allocated for the Lambda. Minimum 128. Maximum 1536. Only accepts
|
81
|
-
# integers in multiples of 64.
|
82
|
-
def deploy_lambda(
|
83
|
-
bucket, key, version_id, function_name, handler, lambda_role, lambda_description = 'Deployed with LambdaWrap',
|
84
|
-
vpc_subnet_ids = [], vpc_security_group_ids = [], runtime = 'nodejs4.3', timeout = 5, memory_size = 128
|
85
|
-
)
|
86
|
-
# create or update function
|
87
|
-
|
88
|
-
begin
|
89
|
-
@client.get_function(function_name: function_name)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
func_config
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
#
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module LambdaWrap
|
4
|
+
##
|
5
|
+
# The LambdaManager simplifies creating a package, publishing to S3, deploying a new version, & setting permissions.
|
6
|
+
#
|
7
|
+
# Note: The concept of an environment of the LambdaWrap gem matches an alias of AWS Lambda.
|
8
|
+
class LambdaManager
|
9
|
+
##
|
10
|
+
# The constructor does some basic setup
|
11
|
+
# * Validating basic AWS configuration
|
12
|
+
# * Creating the underlying client to interace with the AWS SDK
|
13
|
+
def initialize
|
14
|
+
# AWS lambda client
|
15
|
+
@client = Aws::Lambda::Client.new
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Packages a set of files and node modules into a deployable package.
|
20
|
+
#
|
21
|
+
# *Arguments*
|
22
|
+
# [directory] A temporary directory to copy all related files before they are packages into a single zip file.
|
23
|
+
# [zipfile] A path where the deployable package, a zip file, should be stored.
|
24
|
+
# [input_filenames] A list of file names that contain the source code.
|
25
|
+
# [node_modules] A list of node modules that need to be included in the package.
|
26
|
+
def package(directory, zipfile, input_filenames, node_modules)
|
27
|
+
FileUtils.mkdir_p directory
|
28
|
+
FileUtils.mkdir_p File.join(directory, 'node_modules') unless node_modules.empty?
|
29
|
+
|
30
|
+
input_filenames.each do |filename|
|
31
|
+
FileUtils.copy_file(File.join(filename), File.join(directory, File.basename(filename)))
|
32
|
+
end
|
33
|
+
|
34
|
+
node_modules.each do |dir|
|
35
|
+
FileUtils.cp_r(File.join('node_modules', dir), File.join(directory, 'node_modules'))
|
36
|
+
end
|
37
|
+
|
38
|
+
ZipFileGenerator.new(directory, zipfile).write
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Publishes a package to S3 so it can be deployed as a lambda function.
|
43
|
+
#
|
44
|
+
# *Arguments*
|
45
|
+
# [local_lambda_file] The location of the package that needs to be deployed.
|
46
|
+
# [bucket] The s3 bucket where the file needs to be uploaded to.
|
47
|
+
# [key] The S3 path (key) where the package should be stored.
|
48
|
+
def publish_lambda_to_s3(local_lambda_file, bucket, key)
|
49
|
+
# get s3 object
|
50
|
+
s3 = Aws::S3::Resource.new
|
51
|
+
obj = s3.bucket(bucket).object(key)
|
52
|
+
|
53
|
+
# upload
|
54
|
+
version_id = nil
|
55
|
+
File.open(local_lambda_file, 'rb') do |file|
|
56
|
+
version_id = obj.put(body: file).version_id
|
57
|
+
end
|
58
|
+
raise 'Upload to S3 failed' unless version_id
|
59
|
+
|
60
|
+
puts 'Uploaded object to S3 with version ' + version_id
|
61
|
+
version_id
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Deploys a package that has been uploaded to S3.
|
66
|
+
#
|
67
|
+
# *Arguments*
|
68
|
+
# [bucket] The S3 bucket where the package can be retrieved from.
|
69
|
+
# [key] The S3 path (key) where the package can be retrieved from.
|
70
|
+
# [version_id] The version of the file on S3 to retrieve.
|
71
|
+
# [function_name] The name of the lambda function.
|
72
|
+
# [handler] The handler that should be executed for this lambda function.
|
73
|
+
# [lambda_role] The arn of the IAM role that should be used when executing the lambda function.
|
74
|
+
# [lambda_description] The description of the lambda function.
|
75
|
+
# [vpc_subnet_ids] A list of subnet ids for the lambda's VPC configuration. All subnets must be on the same VPC.
|
76
|
+
# [vpc_security_group_ids] A list of security group ids for the lambda's VPC configuration. All of the
|
77
|
+
# security_group_ids must be on the same VPC.
|
78
|
+
# [runtime] The runtime the code is written for.
|
79
|
+
# [timeout] The integer value of seconds until the lambda timesout. Minimum 1, Maximum 300
|
80
|
+
# [memory_size] The Memory/ProcessingPower allocated for the Lambda. Minimum 128. Maximum 1536. Only accepts
|
81
|
+
# integers in multiples of 64.
|
82
|
+
def deploy_lambda(
|
83
|
+
bucket, key, version_id, function_name, handler, lambda_role, lambda_description = 'Deployed with LambdaWrap',
|
84
|
+
vpc_subnet_ids = [], vpc_security_group_ids = [], runtime = 'nodejs4.3', timeout = 5, memory_size = 128
|
85
|
+
)
|
86
|
+
# create or update function
|
87
|
+
|
88
|
+
begin
|
89
|
+
@client.get_function(function_name: function_name)
|
90
|
+
unless vpc_subnet_ids.empty? && vpc_security_group_ids.empty?
|
91
|
+
vpc_configuration = {
|
92
|
+
subnet_ids: vpc_subnet_ids,
|
93
|
+
security_group_ids: vpc_security_group_ids
|
94
|
+
}
|
95
|
+
end
|
96
|
+
func_config = @client.update_function_configuration(
|
97
|
+
function_name: function_name, role: lambda_role, runtime: runtime,
|
98
|
+
handler: handler, timeout: timeout, memory_size: memory_size,
|
99
|
+
description: lambda_description,
|
100
|
+
vpc_config: vpc_configuration
|
101
|
+
).data
|
102
|
+
puts func_config
|
103
|
+
|
104
|
+
func_config = @client.update_function_code(
|
105
|
+
function_name: function_name, s3_bucket: bucket, s3_key: key,
|
106
|
+
s3_object_version: version_id, publish: true
|
107
|
+
).data
|
108
|
+
|
109
|
+
puts func_config
|
110
|
+
func_version = func_config.version
|
111
|
+
raise 'Error while publishing existing lambda function ' + function_name unless func_version
|
112
|
+
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
113
|
+
# check if vpc_subnet_ids and vpc_security_group_ids are empty or not and set the vpc_config accordingly.
|
114
|
+
if vpc_subnet_ids.empty? && vpc_security_group_ids.empty?
|
115
|
+
vpc_configuration = nil
|
116
|
+
else
|
117
|
+
vpc_configuration = { subnet_ids: vpc_subnet_ids, security_group_ids: vpc_security_group_ids }
|
118
|
+
end
|
119
|
+
|
120
|
+
# if we cannot find it, we have to create it instead of updating it
|
121
|
+
func_config = @client.create_function(
|
122
|
+
function_name: function_name, runtime: runtime, role: lambda_role,
|
123
|
+
handler: handler, code: { s3_bucket: bucket, s3_key: key },
|
124
|
+
timeout: timeout, memory_size: memory_size, publish: true,
|
125
|
+
description: lambda_description,
|
126
|
+
vpc_config: vpc_configuration
|
127
|
+
).data
|
128
|
+
|
129
|
+
puts func_config
|
130
|
+
func_version = func_config.version
|
131
|
+
raise "Error while publishing new lambda function #{function_name}" unless func_version
|
132
|
+
end
|
133
|
+
|
134
|
+
add_api_gateway_permissions(function_name, nil)
|
135
|
+
|
136
|
+
# return the version of the new code, not the config.
|
137
|
+
func_version
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Creates an alias for a given lambda function version.
|
142
|
+
#
|
143
|
+
# *Arguments*
|
144
|
+
# [function_name] The lambda function name for which the alias should be created.
|
145
|
+
# [func_version] The lambda function versino to which the alias should point.
|
146
|
+
# [alias_name] The name of the alias, matching the LambdaWrap environment concept.
|
147
|
+
def create_alias(function_name, func_version, alias_name)
|
148
|
+
# create or update alias
|
149
|
+
func_alias = @client.list_aliases(function_name: function_name).aliases.select { |a| a.name == alias_name }.first
|
150
|
+
a = if !func_alias
|
151
|
+
@client.create_alias(
|
152
|
+
function_name: function_name, name: alias_name, function_version: func_version,
|
153
|
+
description: 'created by an automated script'
|
154
|
+
).data
|
155
|
+
else
|
156
|
+
@client.update_alias(
|
157
|
+
function_name: function_name, name: alias_name, function_version: func_version,
|
158
|
+
description: 'updated by an automated script'
|
159
|
+
).data
|
160
|
+
end
|
161
|
+
puts a
|
162
|
+
|
163
|
+
add_api_gateway_permissions(function_name, alias_name)
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
# Removes an alias for a function.
|
168
|
+
#
|
169
|
+
# *Arguments*
|
170
|
+
# [function_name] The lambda function name for which the alias should be removed.
|
171
|
+
# [alias_name] The alias to remove.
|
172
|
+
def remove_alias(function_name, alias_name)
|
173
|
+
@client.delete_alias(function_name: function_name, name: alias_name)
|
174
|
+
end
|
175
|
+
|
176
|
+
##
|
177
|
+
# Adds permissions for API gateway to execute this function.
|
178
|
+
#
|
179
|
+
# *Arguments*
|
180
|
+
# [function_name] The function name which needs to be executed from API Gateway.
|
181
|
+
# [env] The environment (matching the function's alias) which needs to be executed from API Gateway.
|
182
|
+
# => If nil, the permissions are set of the $LATEST version.
|
183
|
+
def add_api_gateway_permissions(function_name, env)
|
184
|
+
# permissions to execute lambda
|
185
|
+
suffix = (':' + env if env) || ''
|
186
|
+
func = @client.get_function(function_name: function_name + suffix).data.configuration
|
187
|
+
statement_id = func.function_name + (('-' + env if env) || '')
|
188
|
+
begin
|
189
|
+
existing_policies = @client.get_policy(function_name: func.function_arn).data
|
190
|
+
existing_policy = JSON.parse(existing_policies.policy)
|
191
|
+
policy_exists = existing_policy['Statement'].select { |s| s['Sid'] == statement_id }.any?
|
192
|
+
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
193
|
+
# policy does not exist, and that is ok
|
194
|
+
policy_exists = false
|
195
|
+
end
|
196
|
+
|
197
|
+
unless policy_exists
|
198
|
+
perm_add = @client.add_permission(
|
199
|
+
function_name: func.function_arn, statement_id: statement_id,
|
200
|
+
action: 'lambda:*', principal: 'apigateway.amazonaws.com'
|
201
|
+
)
|
202
|
+
puts perm_add.data
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
private :add_api_gateway_permissions
|
207
|
+
end
|
208
|
+
end
|
@@ -10,7 +10,7 @@ module LambdaWrap
|
|
10
10
|
# * Creating the underlying client to interact with the AWS SDK.
|
11
11
|
# * Defining the temporary path of the api-gateway-importer jar file
|
12
12
|
def initialize
|
13
|
-
@s3bucket = Aws::S3::Client.new
|
13
|
+
@s3bucket = Aws::S3::Client.new
|
14
14
|
end
|
15
15
|
|
16
16
|
##
|
@@ -21,15 +21,12 @@ module LambdaWrap
|
|
21
21
|
# [policy] Policy to be added to the bucket
|
22
22
|
def setup_policy(s3_bucket_name, policy)
|
23
23
|
# Validate the parameters
|
24
|
-
raise
|
25
|
-
raise
|
24
|
+
raise 'S3 bucket is not provided' unless s3_bucket_name
|
25
|
+
raise 'Policy json is not provided' unless policy
|
26
26
|
|
27
|
-
@s3bucket.put_bucket_policy(
|
28
|
-
|
29
|
-
policy: policy.to_json
|
30
|
-
})
|
27
|
+
@s3bucket.put_bucket_policy(bucket: s3_bucket_name,
|
28
|
+
policy: policy.to_json)
|
31
29
|
puts "Created/Updated policy: #{policy} in S3 bucket #{s3_bucket_name}"
|
32
30
|
end
|
33
|
-
|
34
31
|
end
|
35
32
|
end
|
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'zip'
|
3
|
-
|
4
|
-
module LambdaWrap
|
5
|
-
##
|
6
|
-
# Allows to easily zip a directory recursively. It's intended for gem internal use only.
|
7
|
-
#
|
8
|
-
# From the original example:
|
9
|
-
# This is a simple example which uses rubyzip to
|
10
|
-
# recursively generate a zip file from the contents of
|
11
|
-
# a specified directory. The directory itself is not
|
12
|
-
# included in the archive, rather just its contents.
|
13
|
-
#
|
14
|
-
# Usage:
|
15
|
-
# require /path/to/the/ZipFileGenerator/Class
|
16
|
-
# directoryToZip = "/tmp/input"
|
17
|
-
# outputFile = "/tmp/out.zip"
|
18
|
-
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
|
19
|
-
# zf.write()
|
20
|
-
class ZipFileGenerator
|
21
|
-
##
|
22
|
-
# Initialize with the directory to zip and the location of the output archive.
|
23
|
-
def initialize(input_dir, output_file)
|
24
|
-
@input_dir = input_dir
|
25
|
-
@output_file = output_file
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Zip the input directory.
|
30
|
-
def write
|
31
|
-
entries = Dir.entries(@input_dir) - %w
|
32
|
-
|
33
|
-
Zip::File.open(@output_file, Zip::File::CREATE) do |io|
|
34
|
-
write_entries entries, '', io
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# A helper method to make the recursion work.
|
41
|
-
def write_entries(entries, path, io)
|
42
|
-
entries.each do |e|
|
43
|
-
zip_file_path = path == '' ? e : File.join(path, e)
|
44
|
-
disk_file_path = File.join(@input_dir, zip_file_path)
|
45
|
-
puts "Deflating #{disk_file_path}"
|
46
|
-
|
47
|
-
if File.directory? disk_file_path
|
48
|
-
recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
49
|
-
else
|
50
|
-
put_into_archive(disk_file_path, io, zip_file_path)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
56
|
-
io.mkdir zip_file_path
|
57
|
-
subdir = Dir.entries(disk_file_path) - %w
|
58
|
-
write_entries subdir, zip_file_path, io
|
59
|
-
end
|
60
|
-
|
61
|
-
def put_into_archive(disk_file_path, io, zip_file_path)
|
62
|
-
io.get_output_stream(zip_file_path) do |f|
|
63
|
-
f.puts(File.open(disk_file_path, 'rb').read)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'zip'
|
3
|
+
|
4
|
+
module LambdaWrap
|
5
|
+
##
|
6
|
+
# Allows to easily zip a directory recursively. It's intended for gem internal use only.
|
7
|
+
#
|
8
|
+
# From the original example:
|
9
|
+
# This is a simple example which uses rubyzip to
|
10
|
+
# recursively generate a zip file from the contents of
|
11
|
+
# a specified directory. The directory itself is not
|
12
|
+
# included in the archive, rather just its contents.
|
13
|
+
#
|
14
|
+
# Usage:
|
15
|
+
# require /path/to/the/ZipFileGenerator/Class
|
16
|
+
# directoryToZip = "/tmp/input"
|
17
|
+
# outputFile = "/tmp/out.zip"
|
18
|
+
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
|
19
|
+
# zf.write()
|
20
|
+
class ZipFileGenerator
|
21
|
+
##
|
22
|
+
# Initialize with the directory to zip and the location of the output archive.
|
23
|
+
def initialize(input_dir, output_file)
|
24
|
+
@input_dir = input_dir
|
25
|
+
@output_file = output_file
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Zip the input directory.
|
30
|
+
def write
|
31
|
+
entries = Dir.entries(@input_dir) - %w[. ..]
|
32
|
+
|
33
|
+
Zip::File.open(@output_file, Zip::File::CREATE) do |io|
|
34
|
+
write_entries entries, '', io
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# A helper method to make the recursion work.
|
41
|
+
def write_entries(entries, path, io)
|
42
|
+
entries.each do |e|
|
43
|
+
zip_file_path = path == '' ? e : File.join(path, e)
|
44
|
+
disk_file_path = File.join(@input_dir, zip_file_path)
|
45
|
+
puts "Deflating #{disk_file_path}"
|
46
|
+
|
47
|
+
if File.directory? disk_file_path
|
48
|
+
recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
49
|
+
else
|
50
|
+
put_into_archive(disk_file_path, io, zip_file_path)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
56
|
+
io.mkdir zip_file_path
|
57
|
+
subdir = Dir.entries(disk_file_path) - %w[. ..]
|
58
|
+
write_entries subdir, zip_file_path, io
|
59
|
+
end
|
60
|
+
|
61
|
+
def put_into_archive(disk_file_path, io, zip_file_path)
|
62
|
+
io.get_output_stream(zip_file_path) do |f|
|
63
|
+
f.puts(File.open(disk_file_path, 'rb').read)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/lambda_wrap.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# :nodoc:
|
2
|
-
Dir["#{File.expand_path(File.dirname(__FILE__))}/**/*.rb"].each { |f| require f }
|
3
|
-
|
4
|
-
STDOUT.sync = true
|
5
|
-
STDERR.sync = true
|
1
|
+
# :nodoc:
|
2
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/**/*.rb"].each { |f| require f }
|
3
|
+
|
4
|
+
STDOUT.sync = true
|
5
|
+
STDERR.sync = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lambda_wrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.26.
|
4
|
+
version: 0.26.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Thurner
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk
|
@@ -40,9 +40,11 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '1.2'
|
43
|
-
description:
|
44
|
-
|
45
|
-
|
43
|
+
description: |-
|
44
|
+
This gem wraps the AWS SDK to simplify deployment of AWS \
|
45
|
+
Lambda functions backed by API Gateway and DynamoDB.
|
46
|
+
email:
|
47
|
+
- theodorecarmstrong@gmail.com
|
46
48
|
executables: []
|
47
49
|
extensions: []
|
48
50
|
extra_rdoc_files: []
|
@@ -52,6 +54,7 @@ files:
|
|
52
54
|
- lib/lambda_wrap/dynamo_db_manager.rb
|
53
55
|
- lib/lambda_wrap/lambda_manager.rb
|
54
56
|
- lib/lambda_wrap/s3_bucket_manager.rb
|
57
|
+
- lib/lambda_wrap/version.rb
|
55
58
|
- lib/lambda_wrap/zip_file_generator.rb
|
56
59
|
homepage: https://github.com/Cimpress-MCP/LambdaWrap
|
57
60
|
licenses:
|
@@ -73,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
76
|
version: '0'
|
74
77
|
requirements: []
|
75
78
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.4.5
|
77
80
|
signing_key:
|
78
81
|
specification_version: 4
|
79
82
|
summary: Easy deployment of AWS Lambda functions and dependencies.
|