Class: Jarbs::Lambda
- Inherits:
-
Object
- Object
- Jarbs::Lambda
- Includes:
- Commander::UI, CrashReporter::DSL
- Defined in:
- lib/jarbs/lambda.rb
Instance Attribute Summary collapse
-
#function ⇒ Object
Returns the value of attribute function.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #deploy ⇒ Object
- #deployed? ⇒ Boolean
- #exists? ⇒ Boolean
- #generate ⇒ Object
- #info ⇒ Object
-
#initialize(name, options) ⇒ Lambda
constructor
A new instance of Lambda.
- #update ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Lambda
Returns a new instance of Lambda.
17 18 19 20 21 22 |
# File 'lib/jarbs/lambda.rb', line 17 def initialize(name, ) @options = @function = FunctionDefinition.new(name, @options.env) @client = Aws::Lambda::Client.new region: default_region end |
Instance Attribute Details
#function ⇒ Object
Returns the value of attribute function.
15 16 17 |
# File 'lib/jarbs/lambda.rb', line 15 def function @function end |
Instance Method Details
#create ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jarbs/lambda.rb', line 32 def create data = prepare_for_aws role = @options[:role] || ask("IAM role for function: ") say "Creating #{@function.env_name} on Lambda..." capture_errors do @client.create_function function_name: @function.env_name, runtime: 'nodejs', handler: 'index.handler', role: role, memory_size: 128, timeout: 10, code: { zip_file: data } end say_ok "Complete!" end |
#delete ⇒ Object
63 64 65 66 |
# File 'lib/jarbs/lambda.rb', line 63 def delete res = @client.delete_function function_name: @function.env_name say_ok "Removed #{@function.env_name}." if res.successful? end |
#deploy ⇒ Object
28 29 30 |
# File 'lib/jarbs/lambda.rb', line 28 def deploy deployed? ? update : create end |
#deployed? ⇒ Boolean
72 73 74 75 76 |
# File 'lib/jarbs/lambda.rb', line 72 def deployed? true if info rescue Aws::Lambda::Errors::ResourceNotFoundException => e false end |
#exists? ⇒ Boolean
78 79 80 |
# File 'lib/jarbs/lambda.rb', line 78 def exists? Dir.exists? function.source_path end |
#generate ⇒ Object
24 25 26 |
# File 'lib/jarbs/lambda.rb', line 24 def generate FunctionGenerator.new(@function).generate end |
#info ⇒ Object
68 69 70 |
# File 'lib/jarbs/lambda.rb', line 68 def info @client.get_function(function_name: @function.env_name) end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jarbs/lambda.rb', line 51 def update data = prepare_for_aws say "Updating #{@function.env_name} on Lambda..." capture_errors do @client.update_function_code function_name: @function.env_name, zip_file: data end say_ok "Complete!" end |