lamma 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +21 -0
- data/README.md +12 -39
- data/lamma.gemspec +3 -0
- data/lib/lamma/alias.rb +2 -2
- data/lib/lamma/cli.rb +2 -0
- data/lib/lamma/cli/deploy.rb +36 -42
- data/lib/lamma/cli/init.rb +86 -9
- data/lib/lamma/cli/rollback.rb +10 -5
- data/lib/lamma/cli/show.rb +1 -1
- data/lib/lamma/code.rb +40 -32
- data/lib/lamma/error.rb +6 -0
- data/lib/lamma/function.rb +20 -10
- data/lib/lamma/runtime.rb +15 -14
- data/lib/lamma/shared_helpers.rb +56 -0
- data/lib/lamma/templates/python2_7/lamma.yml.erb +5 -4
- data/lib/lamma/version.rb +1 -1
- metadata +36 -5
- data/lib/lamma/event_source_mapping.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c666ef5bf2f86912462d63b6e29c20165c1bfd
|
4
|
+
data.tar.gz: bb28bc07806ce282888ceb94431b56d513fc42f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a53c581460c7981e90c9258f169b0180b7fd3d7b254b4448f7acbf939ce844ffebc45662c010e699c0641cabb11252fb1d0a205b299957335f5d1565d3acdbe
|
7
|
+
data.tar.gz: 8642d8f477ca8ac025c7b52be42504395a3f6a49bbbc1030c60f9e624f161eec960b9028ab24ecdd99387f7c96b04c6dc3d61e39ab0dbfa36c117d873e711fff
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby
|
8
|
+
fixme:
|
9
|
+
enabled: true
|
10
|
+
rubocop:
|
11
|
+
enabled: true
|
12
|
+
ratings:
|
13
|
+
paths:
|
14
|
+
- "**.rb"
|
15
|
+
- "bin/*"
|
16
|
+
- "exe/*"
|
17
|
+
exclude_paths:
|
18
|
+
- lamma.gemspec
|
19
|
+
- "*.md"
|
20
|
+
- spec/**/*
|
21
|
+
- Rakefile
|
data/README.md
CHANGED
@@ -35,42 +35,15 @@ export AWS_ACCESS_KEY_ID = [YOUR_AWS_ACCESS_KEY_ID]
|
|
35
35
|
export AWS_SECRET_ACCESS_KEY = [YOUR_AWS_SECRET_ACCESS_KEY]
|
36
36
|
```
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Make some change on nodejs/python2.7 function and
|
51
|
-
|
52
|
-
```
|
53
|
-
lamma deploy production(or development)
|
54
|
-
```
|
55
|
-
![create]()
|
56
|
-
![console]()
|
57
|
-
|
58
|
-
### Rollback last deploy
|
59
|
-
|
60
|
-
```
|
61
|
-
lamma rollback production(or development)
|
62
|
-
```
|
63
|
-
![before]()
|
64
|
-
![after]()
|
65
|
-
|
66
|
-
### Recommended setting
|
67
|
-
It is recommended to connect your lambda with an event source via PROD/DEV version aliases,
|
68
|
-
so that you can keep the mapping before/after the deployment/rollback.
|
69
|
-
([see also](https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html))
|
70
|
-
|
71
|
-
End-to-end functionalities for
|
72
|
-
- Managing event-source-mappings,
|
73
|
-
- Creating IAM roles
|
74
|
-
|
75
|
-
will be supported in future release.
|
76
|
-
|
38
|
+
# Todo
|
39
|
+
- [ ] Support Automatic IAM Role initialization
|
40
|
+
- [ ] Support dead letter queue configuration
|
41
|
+
- [ ] Support environment variables
|
42
|
+
- [ ] Support KMS encripted variable configuration
|
43
|
+
- [ ] Support VPC configuration
|
44
|
+
- [ ] Prepare init templates
|
45
|
+
- [x] python2.7
|
46
|
+
- [ ] node4.3
|
47
|
+
- [ ] node4.3 edge
|
48
|
+
- [ ] C#
|
49
|
+
- [ ] Java8
|
data/lamma.gemspec
CHANGED
@@ -18,12 +18,15 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.bindir = "exe"
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
|
+
spec.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.
|
21
22
|
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
25
|
spec.add_development_dependency "rspec", "~> 3"
|
26
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
25
27
|
|
26
28
|
spec.add_dependency "aws-sdk", "~> 2"
|
27
29
|
spec.add_dependency "thor", "~> 0.19"
|
28
30
|
spec.add_dependency "rubyzip", "~> 1.2"
|
31
|
+
spec.add_dependency "inifile", "~> 3.0"
|
29
32
|
end
|
data/lib/lamma/alias.rb
CHANGED
@@ -28,7 +28,7 @@ module Lamma
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def create_or_update
|
31
|
-
if
|
31
|
+
if remote_exist?
|
32
32
|
update
|
33
33
|
else
|
34
34
|
create
|
@@ -39,7 +39,7 @@ module Lamma
|
|
39
39
|
@name.upcase
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def remote_exist?
|
43
43
|
begin
|
44
44
|
lambda_client.get_alias({
|
45
45
|
function_name: @function.name,
|
data/lib/lamma/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require 'thor'
|
|
4
4
|
module Lamma
|
5
5
|
class CLI < Thor
|
6
6
|
class_option :verbose, aliases: '-v', type: :boolean
|
7
|
+
class_option :profile, aliases: '-p', type: :string
|
7
8
|
map '--version' => :print_version
|
8
9
|
|
9
10
|
desc 'list', 'List lambda functions in AWS'
|
@@ -44,6 +45,7 @@ module Lamma
|
|
44
45
|
|
45
46
|
desc 'init FUNCTION_NAME', 'Initialize local function'
|
46
47
|
method_option :runtime, aliases: '-r', type: :string, required: true
|
48
|
+
method_option :role_arn, aliases: %w(--role-arn -R), type: :string
|
47
49
|
def init(function_name)
|
48
50
|
require 'lamma/cli/init'
|
49
51
|
Init.new(options, function_name, self).run
|
data/lib/lamma/cli/deploy.rb
CHANGED
@@ -3,76 +3,70 @@ require 'yaml'
|
|
3
3
|
require 'lamma'
|
4
4
|
require 'lamma/function'
|
5
5
|
require 'lamma/alias'
|
6
|
+
require 'lamma/shared_helpers'
|
6
7
|
|
7
8
|
module Lamma
|
8
9
|
class CLI::Deploy
|
10
|
+
include SharedHelpers
|
11
|
+
|
9
12
|
attr_reader :options, :thor
|
10
13
|
|
11
14
|
def initialize(options, thor)
|
12
15
|
@options = options
|
13
16
|
@thor = thor
|
14
|
-
@conf_path = options['path'] || Lamma::DEFAULT_CONF_PATH
|
17
|
+
@conf_path = search_conf_path(options['path'] || Lamma::DEFAULT_CONF_PATH)
|
15
18
|
end
|
16
19
|
|
17
20
|
def run
|
18
|
-
unless File.
|
21
|
+
unless File.exist?(@conf_path)
|
19
22
|
abort("Config file #{@conf_path} is missing.")
|
20
23
|
end
|
21
24
|
|
22
25
|
f = Lamma::Function.new(@conf_path)
|
26
|
+
update_or_create_function(f)
|
23
27
|
|
24
|
-
|
25
|
-
thor.say("Function #{function.name} doesn't seem to be exist on remote.", :yellow)
|
26
|
-
y_or_n = thor.ask("Do you want me to create it? (y/n)", :yellow)
|
28
|
+
new_version = f.publish_version(options['message']).version
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
30
|
+
if options['alias']
|
31
|
+
update_or_create_alias(f, new_version)
|
31
32
|
end
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
new_version = f.publish_version(options['message']).version
|
35
|
+
private
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
def update_or_create_alias(f, new_version)
|
38
|
+
a = Lamma::Alias.new(f, options['alias'], new_version)
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
if a.remote_exist? && a.remote_version
|
41
|
+
last_version = a.remote_version
|
42
|
+
a.update
|
43
|
+
else
|
44
|
+
last_version = new_version
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
thor.say("Function alias #{a.name} doesn't seem to be exist on remote.", :yellow)
|
47
|
+
y_or_n = thor.ask("Do you want me to create it? (y/n)", :yellow)
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
49
|
+
if y_or_n =~ /^[yY]/
|
50
|
+
a.create
|
51
|
+
else
|
52
|
+
abort('Canceled')
|
53
53
|
end
|
54
|
-
|
55
|
-
la = Lamma::Alias.new(f, "#{@options['alias']}_#{Lamma::LAST_DEPLOY_SUFFIX}", last_version)
|
56
|
-
la.create_or_update
|
57
54
|
end
|
55
|
+
|
56
|
+
la = Lamma::Alias.new(f, "#{@options['alias']}_#{Lamma::LAST_DEPLOY_SUFFIX}", last_version)
|
57
|
+
la.create_or_update
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
def update_or_create_function(f)
|
61
|
+
if f.remote_exist?
|
62
|
+
f.update
|
63
|
+
else
|
64
|
+
thor.say("Function #{f.name} doesn't seem to be exist on remote.", :yellow)
|
65
|
+
y_or_n = thor.ask("Do you want me to create it? (y/n)", :yellow)
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
rescue ArgumentError
|
66
|
-
thor.say("ArgumentError occured. You might need to specify role arn \
|
67
|
-
you want to pass to your function via 'lamma.conf' file or ENV['AWS_LAMBDA_IAM_ROLE'].", :red)
|
68
|
-
return
|
69
|
-
end
|
70
|
-
thor.say("Done.", :blue)
|
71
|
-
thor.say("Setting aliases.", :yellow)
|
72
|
-
first_version = function.publish_version.version
|
73
|
-
Lamma::Function::ENVIRONMENT_ALIAS_NAME_MAP.values.each do |alias_name|
|
74
|
-
function.create_alias(alias_name, first_version)
|
75
|
-
function.create_alias(alias_name << '_LAST', first_version)
|
67
|
+
if y_or_n =~ /^[yY]/
|
68
|
+
f.create
|
69
|
+
end
|
76
70
|
end
|
77
71
|
end
|
78
72
|
end
|
data/lib/lamma/cli/init.rb
CHANGED
@@ -1,16 +1,43 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
1
4
|
require 'pathname'
|
5
|
+
|
6
|
+
require 'lamma/logger'
|
2
7
|
require 'lamma/runtime'
|
8
|
+
require 'lamma/shared_helpers'
|
3
9
|
|
4
10
|
module Lamma
|
5
11
|
class CLI::Init
|
6
12
|
include Thor::Actions
|
7
|
-
|
13
|
+
include Lamma::SharedHelpers
|
14
|
+
|
15
|
+
ROLE_ARN_PLACEHOLDER = 'YOUR_ROLE_ARN'
|
16
|
+
|
17
|
+
DEFAULT_LAMBDA_ASSUME_ROLE_POLICY =
|
18
|
+
{
|
19
|
+
'Version': '2012-10-17',
|
20
|
+
'Statement':
|
21
|
+
[
|
22
|
+
{
|
23
|
+
'Effect': 'Allow',
|
24
|
+
'Principal':
|
25
|
+
{
|
26
|
+
'Service': 'lambda.amazonaws.com'
|
27
|
+
},
|
28
|
+
'Action': 'sts:AssumeRole',
|
29
|
+
},
|
30
|
+
],
|
31
|
+
}
|
32
|
+
|
33
|
+
attr_reader :target, :thor, :options, :runtime, :function_name
|
8
34
|
|
9
35
|
def initialize(options, function_name, thor)
|
10
36
|
@options = options
|
11
37
|
@thor = thor
|
12
38
|
runtime_str = options.fetch('runtime') { raise ArgumentError.new('runtime must be set.') }
|
13
39
|
@runtime = Lamma::Runtime.new(runtime_str)
|
40
|
+
@function_name = function_name
|
14
41
|
@target = Pathname.pwd.join(function_name)
|
15
42
|
end
|
16
43
|
|
@@ -26,11 +53,27 @@ module Lamma
|
|
26
53
|
[File.expand_path(path), File.join(target, tar_file)]
|
27
54
|
end.to_h
|
28
55
|
|
29
|
-
unless Dir.
|
56
|
+
unless Dir.exist?(target)
|
30
57
|
FileUtils.makedirs(target)
|
31
58
|
end
|
32
59
|
|
60
|
+
role_arn = options['role_arn']
|
61
|
+
|
62
|
+
unless role_arn
|
63
|
+
role_name = "#{function_name}-lamma-role"
|
64
|
+
thor.say("Looks like you didn't specified role arn for the function.", :yellow)
|
65
|
+
y_or_n = thor.ask("Do you want me to create default IAM role and configure it (#{role_name})? (y/n)", :yellow)
|
66
|
+
|
67
|
+
if y_or_n =~ /^[yY]/
|
68
|
+
role_arn = create_initial_role(role_name)
|
69
|
+
else
|
70
|
+
role_arn = 'YOUR_ROLE_ARN'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
33
74
|
templates.each do |src, dst|
|
75
|
+
thor.say_status(:create, dst)
|
76
|
+
|
34
77
|
File.open(dst, "w") do |f|
|
35
78
|
template = File.read(src)
|
36
79
|
formatted = ERB.new(template).result(binding)
|
@@ -38,6 +81,8 @@ module Lamma
|
|
38
81
|
end
|
39
82
|
end
|
40
83
|
|
84
|
+
|
85
|
+
Lamma.logger.info "Initializing git repo in #{target}"
|
41
86
|
Dir.chdir(target) do
|
42
87
|
`git init`
|
43
88
|
`git add .`
|
@@ -46,16 +91,48 @@ module Lamma
|
|
46
91
|
|
47
92
|
private
|
48
93
|
|
49
|
-
def
|
50
|
-
|
94
|
+
def iam
|
95
|
+
Aws::IAM::Client.new
|
51
96
|
end
|
52
97
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
98
|
+
def create_initial_role(role_name)
|
99
|
+
begin
|
100
|
+
Lamma.logger.info("Creating role #{role_name}")
|
101
|
+
resp = iam.create_role({
|
102
|
+
assume_role_policy_document: DEFAULT_LAMBDA_ASSUME_ROLE_POLICY.to_json,
|
103
|
+
path: "/",
|
104
|
+
role_name: role_name
|
105
|
+
})
|
106
|
+
rescue Aws::IAM::Errors::EntityAlreadyExists
|
107
|
+
thor.say("Role #{role_name} seems to be created before", :yellow)
|
108
|
+
y_or_n = thor.ask("Do you want me to configure the role (#{role_name})? (y/n)", :yellow)
|
109
|
+
|
110
|
+
unless y_or_n =~ /^[yY]/
|
111
|
+
return ROLE_ARN_PLACEHOLDER
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
Lamma.logger.info("Checking attached role policies for #{role_name}")
|
116
|
+
|
117
|
+
g_resp = iam.get_role({
|
118
|
+
role_name: role_name
|
119
|
+
})
|
120
|
+
role_arn = g_resp.role.arn
|
121
|
+
|
122
|
+
unless iam.list_attached_role_policies({role_name: role_name }).attached_policies
|
123
|
+
.any?{|po| po.policy_name == 'AWSLambdaBasicExecutionRole'}
|
124
|
+
Lamma.logger.info('Could not find AWSLambdaBasicExecutionRole policy. Attatching.')
|
125
|
+
|
126
|
+
Lamma.logger.info("Attaching minimal policy (AWSLambdaBasicExecutionRole) to #{role_name}")
|
127
|
+
resp = iam.attach_role_policy({
|
128
|
+
policy_arn: 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole',
|
129
|
+
role_name: role_name
|
130
|
+
})
|
131
|
+
|
132
|
+
Lamma.logger.info("Done")
|
133
|
+
end
|
56
134
|
|
57
|
-
|
58
|
-
nil
|
135
|
+
role_arn
|
59
136
|
end
|
60
137
|
end
|
61
138
|
end
|
data/lib/lamma/cli/rollback.rb
CHANGED
@@ -3,25 +3,28 @@ require 'yaml'
|
|
3
3
|
require 'lamma'
|
4
4
|
require 'lamma/function'
|
5
5
|
require 'lamma/alias'
|
6
|
+
require 'lamma/shared_helpers'
|
6
7
|
|
7
8
|
module Lamma
|
8
9
|
class CLI::Rollback
|
10
|
+
include SharedHelpers
|
11
|
+
|
9
12
|
attr_reader :options, :thor, :path
|
10
13
|
|
11
14
|
def initialize(options, thor)
|
12
15
|
@options = options
|
13
16
|
@thor = thor
|
14
|
-
@conf_path = options['path'] || Lamma::DEFAULT_CONF_PATH
|
17
|
+
@conf_path = search_conf_path(options['path'] || Lamma::DEFAULT_CONF_PATH)
|
15
18
|
end
|
16
19
|
|
17
20
|
def run
|
18
|
-
unless File.
|
21
|
+
unless File.exist?(@conf_path)
|
19
22
|
abort("Config file #{@conf_path} is missing.")
|
20
23
|
end
|
21
24
|
|
22
25
|
f = Lamma::Function.new(@conf_path)
|
23
26
|
|
24
|
-
unless f.
|
27
|
+
unless f.remote_exist?
|
25
28
|
abort("Remote function #{f.name} doesn't seem to be exists. You have to create or deploy it first")
|
26
29
|
end
|
27
30
|
|
@@ -31,13 +34,13 @@ module Lamma
|
|
31
34
|
|
32
35
|
a = Lamma::Alias.new(f, options['alias'])
|
33
36
|
|
34
|
-
unless a.
|
37
|
+
unless a.remote_exist?
|
35
38
|
abort("Alias #{a.name} doesn't exist. You have to deploy the function first.")
|
36
39
|
end
|
37
40
|
|
38
41
|
la = Lamma::Alias.new(f, "#{options['alias']}_#{Lamma::LAST_DEPLOY_SUFFIX}")
|
39
42
|
|
40
|
-
unless la.
|
43
|
+
unless la.remote_exist?
|
41
44
|
abort("Alias #{la.name} doesn't exist. You have to deploy the function first.")
|
42
45
|
end
|
43
46
|
|
@@ -49,6 +52,8 @@ module Lamma
|
|
49
52
|
end
|
50
53
|
|
51
54
|
a.version = lv
|
55
|
+
|
56
|
+
Lamma.logger.info("Updating alias configuration")
|
52
57
|
a.update
|
53
58
|
end
|
54
59
|
|
data/lib/lamma/cli/show.rb
CHANGED
data/lib/lamma/code.rb
CHANGED
@@ -15,9 +15,9 @@ module Lamma
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def zip_io
|
18
|
-
|
18
|
+
h = cached_build_hash
|
19
19
|
|
20
|
-
if h
|
20
|
+
if h
|
21
21
|
bp = File.join(build_path, h, BUILD_FILE_NAME)
|
22
22
|
Lamma.logger.info "Using cached build: #{bp}"
|
23
23
|
@zip_io = File.open(bp, 'rb')
|
@@ -26,37 +26,9 @@ module Lamma
|
|
26
26
|
raise "Source path #{@source_path} doesn't exists"
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
if @prebuild
|
31
|
-
Lamma.logger.info 'Running prebuild script...'
|
32
|
-
raise unless system(@prebuild)
|
33
|
-
elsif @function.runtime == Lamma::Runtime::PYTHON_27 \
|
34
|
-
&& File.exist?(File.join(@source_path, 'requirements.txt'))
|
35
|
-
raise unless system("pip", "install", "-r", "requirements.txt", "-t", ".")
|
36
|
-
# XXX: verbose?
|
37
|
-
elsif [Lamma::Runtime::EDGE_NODE_43, Lamma::Runtime::NODE_43].include? @function.runtime \
|
38
|
-
&& File.exist?(File.join(@source_path, 'package.json'))
|
39
|
-
raise unless system("npm", "install", "--production")
|
40
|
-
end
|
29
|
+
prebuild
|
41
30
|
|
42
|
-
|
43
|
-
active_paths.each do |path|
|
44
|
-
next unless File.file?(path)
|
45
|
-
File.open(path) do |source_io|
|
46
|
-
zio.put_next_entry(path)
|
47
|
-
data = source_io.read
|
48
|
-
zio.write(data)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
io.rewind
|
54
|
-
if true # XXX: option save_builds?
|
55
|
-
File.open(File.join(zipfile_path, BUILD_FILE_NAME), 'w').write(io.read)
|
56
|
-
Lamma.logger.info("Saved the build: #{zipfile_path}")
|
57
|
-
io.rewind
|
58
|
-
end
|
59
|
-
@zip_io = io
|
31
|
+
@zip_io = zip_and_save
|
60
32
|
end
|
61
33
|
|
62
34
|
@zip_io
|
@@ -70,6 +42,42 @@ module Lamma
|
|
70
42
|
|
71
43
|
private
|
72
44
|
|
45
|
+
def zip_and_save
|
46
|
+
io = Zip::OutputStream.write_buffer do |zio|
|
47
|
+
active_paths.each do |path|
|
48
|
+
next unless File.file?(path)
|
49
|
+
File.open(path) do |source_io|
|
50
|
+
zio.put_next_entry(path)
|
51
|
+
data = source_io.read
|
52
|
+
zio.write(data)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
io.rewind
|
58
|
+
|
59
|
+
if true # XXX: option save_builds?
|
60
|
+
File.open(File.join(zipfile_path, BUILD_FILE_NAME), 'w').write(io.read)
|
61
|
+
Lamma.logger.info("Saved the build: #{zipfile_path}")
|
62
|
+
io.rewind
|
63
|
+
end
|
64
|
+
|
65
|
+
io
|
66
|
+
end
|
67
|
+
|
68
|
+
def prebuild
|
69
|
+
if @prebuild
|
70
|
+
Lamma.logger.info 'Running prebuild script...'
|
71
|
+
raise unless system(@prebuild)
|
72
|
+
elsif @function.runtime == Lamma::Runtime::PYTHON_27 \
|
73
|
+
&& File.exist?(File.join(@source_path, 'requirements.txt'))
|
74
|
+
raise unless system("pip", "install", "-r", "requirements.txt", "-t", ".")
|
75
|
+
elsif [Lamma::Runtime::EDGE_NODE_43, Lamma::Runtime::NODE_43].include?(@function.runtime) \
|
76
|
+
&& File.exist?(File.join(@source_path, 'package.json'))
|
77
|
+
raise unless system("npm", "install", "--production")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
73
81
|
def cached_build_hash
|
74
82
|
Dir.glob(File.join(build_path, "*/"))
|
75
83
|
.map{|path| File.basename(path)}.each do |h|
|
data/lib/lamma/error.rb
ADDED
data/lib/lamma/function.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'aws-sdk'
|
1
2
|
require 'pathname'
|
2
3
|
require 'yaml'
|
3
4
|
|
@@ -7,16 +8,24 @@ require 'lamma/code'
|
|
7
8
|
require 'lamma/vpc_config'
|
8
9
|
require 'lamma/dead_letter_config'
|
9
10
|
require 'lamma/environment'
|
11
|
+
require 'lamma/error'
|
10
12
|
|
11
13
|
module Lamma
|
12
14
|
class Function
|
13
|
-
|
15
|
+
# @!attribute [r] name
|
16
|
+
# @return [String]
|
17
|
+
# @!attribute [r] region
|
18
|
+
# @return [String]
|
19
|
+
# @!attribute [r] conf
|
20
|
+
# @return [Hash]
|
21
|
+
# @!attribute [rw] publish
|
22
|
+
# @return [Bool]
|
23
|
+
attr_reader :name, :region, :conf
|
14
24
|
attr_accessor :publish
|
15
25
|
|
26
|
+
# @param [String] yaml_path
|
16
27
|
def initialize(yaml_path)
|
17
28
|
path = Pathname.new(yaml_path)
|
18
|
-
@id = path.basename.sub_ext('').to_s
|
19
|
-
@root_path = path.parent
|
20
29
|
yaml = YAML.load(path.open)
|
21
30
|
|
22
31
|
@conf = yaml.fetch('function', {})
|
@@ -28,10 +37,11 @@ module Lamma
|
|
28
37
|
@timeout = @conf.fetch('timeout', 3)
|
29
38
|
@memory_size = @conf.fetch('memory_size', 128)
|
30
39
|
# @dead_letter_config = dead_letter_config(@conf)
|
31
|
-
@region = @conf.fetch('region') { raise ValidationError.new('region must be set.') }
|
40
|
+
@region = @conf.fetch('region') { raise Lamma::ValidationError.new('region must be set.') }
|
32
41
|
@kms_key_arn = @conf.fetch('kms_key_arn', nil)
|
33
42
|
end
|
34
43
|
|
44
|
+
# @return [Lamma::Code]
|
35
45
|
def code
|
36
46
|
@code ||= Code.new(self, @conf.fetch('code', {}))
|
37
47
|
end
|
@@ -54,7 +64,7 @@ module Lamma
|
|
54
64
|
kms_key_arn: @kms_key_arn
|
55
65
|
})
|
56
66
|
|
57
|
-
Lamma.logger.info(resp)
|
67
|
+
Lamma.logger.info("Created new function #{resp.function_arn}")
|
58
68
|
end
|
59
69
|
|
60
70
|
def update
|
@@ -87,7 +97,7 @@ module Lamma
|
|
87
97
|
end
|
88
98
|
|
89
99
|
def update_or_create
|
90
|
-
if
|
100
|
+
if remote_exist?
|
91
101
|
update
|
92
102
|
else
|
93
103
|
create
|
@@ -119,7 +129,7 @@ module Lamma
|
|
119
129
|
resp
|
120
130
|
end
|
121
131
|
|
122
|
-
def
|
132
|
+
def remote_exist?
|
123
133
|
begin
|
124
134
|
lambda_client.get_function_configuration({
|
125
135
|
function_name: @name,
|
@@ -129,14 +139,14 @@ module Lamma
|
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
132
|
-
private
|
133
|
-
|
134
142
|
def runtime
|
135
|
-
runtime_str = @conf.fetch('runtime') { raise
|
143
|
+
runtime_str = @conf.fetch('runtime') { raise ArgumentError.new('runtime must be set') }
|
136
144
|
|
137
145
|
@runtime ||= Lamma::Runtime.new(runtime_str)
|
138
146
|
end
|
139
147
|
|
148
|
+
private
|
149
|
+
|
140
150
|
def handler
|
141
151
|
@conf.fetch('handler', default_handler)
|
142
152
|
end
|
data/lib/lamma/runtime.rb
CHANGED
@@ -13,20 +13,21 @@ module Lamma
|
|
13
13
|
PYTHON_27 = 40
|
14
14
|
|
15
15
|
def initialize(str)
|
16
|
-
@type =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
@type =
|
17
|
+
case str
|
18
|
+
when /^c[s#](harp)?$/i
|
19
|
+
::Lamma::Runtime::C_SHARP
|
20
|
+
when /^java([-_\.\s]*8?)?$/i
|
21
|
+
::Lamma::Runtime::JAVA_8
|
22
|
+
when /^node([-_\.\s]*4(\.?3)?)?$/i
|
23
|
+
::Lamma::Runtime::NODE_43
|
24
|
+
when /^edge[-_\.\s]*node(\s*4(\.?3)?)?$/i
|
25
|
+
::Lamma::Runtime::EDGE_NODE_43
|
26
|
+
when /^python([-_\.\s]*2(\.?7)?)?$/i
|
27
|
+
::Lamma::Runtime::PYTHON_27
|
28
|
+
else
|
29
|
+
raise ArgumentError.new("invalid runtime. #{str}")
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
33
|
NAME = {
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'inifile'
|
3
|
+
|
4
|
+
|
5
|
+
module Lamma
|
6
|
+
module SharedHelpers
|
7
|
+
DEFAULT_PROFILE = 'default'
|
8
|
+
|
9
|
+
def ini_config(profile=DEFAULT_PROFILE)
|
10
|
+
load_inifile(File.expand_path(File.join('~', '.aws', 'config')), profile)
|
11
|
+
end
|
12
|
+
|
13
|
+
def ini_credentials(profile=DEFAULT_PROFILE)
|
14
|
+
load_inifile(File.expand_path(File.join('~', '.aws', 'credentials')), profile)
|
15
|
+
end
|
16
|
+
|
17
|
+
def region_or_raise(profile=DEFAULT_PROFILE)
|
18
|
+
region = ENV['AWS_REGION'] ||
|
19
|
+
ENV['AWS_DEFAULT_REGION'] ||
|
20
|
+
ini_config(profile)['region']
|
21
|
+
|
22
|
+
if region
|
23
|
+
return region
|
24
|
+
else
|
25
|
+
raise Exception.new("Region must be specified by either AWS_REGION, AWS_DEFAULT_REGION or ~/.aws/config file")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def search_conf_path(from)
|
30
|
+
bn = File.basename(File.expand_path(from))
|
31
|
+
dn = File.dirname(File.expand_path(from))
|
32
|
+
pn = Pathname(dn)
|
33
|
+
|
34
|
+
while pn != pn.parent
|
35
|
+
cp = File.join(pn, bn)
|
36
|
+
if File.exist?(cp)
|
37
|
+
return cp
|
38
|
+
end
|
39
|
+
|
40
|
+
pn = pn.parent
|
41
|
+
end
|
42
|
+
|
43
|
+
''
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def load_inifile(path, profile)
|
49
|
+
if File.exist?(path)
|
50
|
+
return IniFile.load(path)[profile]
|
51
|
+
else
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
name:
|
3
|
-
role_arn:
|
1
|
+
function:
|
2
|
+
name: <%= function_name %>
|
3
|
+
role_arn: <%= role_arn %>
|
4
4
|
description: Hello, world.
|
5
5
|
timeout: 3
|
6
6
|
memory_size: 128
|
7
|
-
|
7
|
+
runtime: python2.7
|
8
|
+
region: <%= region_or_raise %>
|
data/lib/lamma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lamma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichiro Someya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: aws-sdk
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '1.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: inifile
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
97
125
|
description: Deploy toolset for Amazon Lambda functions..
|
98
126
|
email:
|
99
127
|
- ayemos.y@gmail.com
|
@@ -102,6 +130,7 @@ executables:
|
|
102
130
|
extensions: []
|
103
131
|
extra_rdoc_files: []
|
104
132
|
files:
|
133
|
+
- ".codeclimate.yml"
|
105
134
|
- ".gitignore"
|
106
135
|
- ".rspec"
|
107
136
|
- ".rubocop.yml"
|
@@ -127,10 +156,11 @@ files:
|
|
127
156
|
- lib/lamma/code.rb
|
128
157
|
- lib/lamma/dead_letter_config.rb
|
129
158
|
- lib/lamma/environment.rb
|
130
|
-
- lib/lamma/
|
159
|
+
- lib/lamma/error.rb
|
131
160
|
- lib/lamma/function.rb
|
132
161
|
- lib/lamma/logger.rb
|
133
162
|
- lib/lamma/runtime.rb
|
163
|
+
- lib/lamma/shared_helpers.rb
|
134
164
|
- lib/lamma/templates/python2_7/lambda_function.py.erb
|
135
165
|
- lib/lamma/templates/python2_7/lamma.yml.erb
|
136
166
|
- lib/lamma/version.rb
|
@@ -138,7 +168,8 @@ files:
|
|
138
168
|
homepage: https://github.com/ayemos/Lamma
|
139
169
|
licenses:
|
140
170
|
- MIT
|
141
|
-
metadata:
|
171
|
+
metadata:
|
172
|
+
yard.run: yri
|
142
173
|
post_install_message:
|
143
174
|
rdoc_options: []
|
144
175
|
require_paths:
|
@@ -155,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
186
|
version: '0'
|
156
187
|
requirements: []
|
157
188
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.5
|
189
|
+
rubygems_version: 2.4.5
|
159
190
|
signing_key:
|
160
191
|
specification_version: 4
|
161
192
|
summary: Deploy toolset for Amazon Lambda functions.
|