Class: DPL::Provider::Lambda
Instance Attribute Summary
#context, #options
Instance Method Summary
collapse
apt_get, #check_app, #commit_msg, context, #create_key, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #user_agent, #warn
Constructor Details
This class inherits a constructor from DPL::Provider
Instance Method Details
#check_auth ⇒ Object
99
100
101
|
# File 'lib/dpl/provider/lambda.rb', line 99
def check_auth
log "Using Access Key: #{option(:access_key_id)[-4..-1].rjust(20, '*')}"
end
|
#cleanup ⇒ Object
135
136
|
# File 'lib/dpl/provider/lambda.rb', line 135
def cleanup
end
|
#create_zip(dest_file_path, src_directory_path, files) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/dpl/provider/lambda.rb', line 85
def create_zip(dest_file_path, src_directory_path, files)
Zip::File.open(dest_file_path, Zip::File::CREATE) do |zipfile|
files.each do |file|
zipfile.add(file.sub(src_directory_path + File::SEPARATOR, ''), file)
end
end
dest_file_path
end
|
#deafult_memory_size ⇒ Object
123
124
125
|
# File 'lib/dpl/provider/lambda.rb', line 123
def deafult_memory_size
128
end
|
#default_description ⇒ Object
119
120
121
|
# File 'lib/dpl/provider/lambda.rb', line 119
def default_description
"Deploy build #{context.env['TRAVIS_BUILD_NUMBER']} to AWS Lambda via Travis CI"
end
|
#default_mode ⇒ Object
111
112
113
|
# File 'lib/dpl/provider/lambda.rb', line 111
def default_mode
'event'
end
|
#default_module_name ⇒ Object
127
128
129
|
# File 'lib/dpl/provider/lambda.rb', line 127
def default_module_name
'index'
end
|
#default_runtime ⇒ Object
107
108
109
|
# File 'lib/dpl/provider/lambda.rb', line 107
def default_runtime
'nodejs'
end
|
#default_timeout ⇒ Object
115
116
117
|
# File 'lib/dpl/provider/lambda.rb', line 115
def default_timeout
3 end
|
#function_zip ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/dpl/provider/lambda.rb', line 51
def function_zip
target_zip_path = File.absolute_path(options[:zip] || Dir.pwd)
dest_file_path = output_file_path
if File.directory?(target_zip_path)
zip_directory(dest_file_path, target_zip_path)
elsif File.file?(target_zip_path)
zip_file(dest_file_path, target_zip_path)
else
error('Invalid zip option. If set, must be path to directory, js file, or a zip file.')
end
File.new(dest_file_path)
end
|
#handler ⇒ Object
44
45
46
47
48
49
|
# File 'lib/dpl/provider/lambda.rb', line 44
def handler
module_name = options[:module_name] || default_module_name
handler_name = option(:handler_name)
"#{module_name}.#{handler_name}"
end
|
#lambda ⇒ Object
11
12
13
|
# File 'lib/dpl/provider/lambda.rb', line 11
def lambda
@lambda ||= ::Aws::LambdaPreview::Client.new(lambda_options)
end
|
#lambda_options ⇒ Object
15
16
17
18
19
20
|
# File 'lib/dpl/provider/lambda.rb', line 15
def lambda_options
{
region: options[:region] || 'us-east-1',
credentials: ::Aws::Credentials.new(option(:access_key_id), option(:secret_access_key))
}
end
|
#needs_key? ⇒ Boolean
95
96
97
|
# File 'lib/dpl/provider/lambda.rb', line 95
def needs_key?
false
end
|
#output_file_path ⇒ Object
103
104
105
|
# File 'lib/dpl/provider/lambda.rb', line 103
def output_file_path
@output_file_path ||= '/tmp/' + random_chars(8) + '-lambda.zip'
end
|
#push_app ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/dpl/provider/lambda.rb', line 22
def push_app
response = lambda.upload_function({
function_name: options[:name] || option(:function_name),
description: options[:description] || default_description,
timeout: options[:timeout] || default_timeout,
memory_size: options[:memory_size] || deafult_memory_size,
role: option(:role),
handler: handler,
function_zip: function_zip,
runtime: default_runtime,
mode: default_mode
})
log "Uploaded lambda: #{response.function_name}."
rescue ::Aws::LambdaPreview::Errors::ServiceException => exception
error(exception.message)
rescue ::Aws::LambdaPreview::Errors::InvalidParameterValueException => exception
error(exception.message)
rescue ::Aws::LambdaPreview::Errors::ResourceNotFoundException => exception
error(exception.message)
end
|
#random_chars(count = 8) ⇒ Object
131
132
133
|
# File 'lib/dpl/provider/lambda.rb', line 131
def random_chars(count=8)
(36**(count-1) + rand(36**count - 36**(count-1))).to_s(36)
end
|
#uncleanup ⇒ Object
138
139
|
# File 'lib/dpl/provider/lambda.rb', line 138
def uncleanup
end
|
#zip_directory(dest_file_path, target_directory_path) ⇒ Object
80
81
82
83
|
# File 'lib/dpl/provider/lambda.rb', line 80
def zip_directory(dest_file_path, target_directory_path)
files = Dir[File.join(target_directory_path, '**', '**')]
create_zip(dest_file_path, target_directory_path, files)
end
|
#zip_file(dest_file_path, target_file_path) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/dpl/provider/lambda.rb', line 66
def zip_file(dest_file_path, target_file_path)
if File.extname(target_file_path) == '.zip'
FileUtils.cp(target_file_path, dest_file_path)
dest_file_path
else
src_directory_path = File.dirname(target_file_path)
files = [ target_file_path ]
create_zip(dest_file_path, src_directory_path, files)
end
end
|