Module: Jets::Stack::Main::Dsl::Lambda
- Defined in:
- lib/jets/stack/main/dsl/lambda.rb
Instance Method Summary collapse
-
#function(id, props = {}) ⇒ Object
(also: #ruby_function, #lambda_function)
Example:.
- #node_function(id, props = {}) ⇒ Object
-
#permission(id, props = {}) ⇒ Object
Usage:.
- #python_function(id, props = {}) ⇒ Object
Instance Method Details
#function(id, props = {}) ⇒ Object Also known as: ruby_function, lambda_function
Example:
function(:hello,
handler: handler("hello.lambda_hander"),
runtime: "python3.6"
)
Defaults to ruby. So:
function(:hello)
is the same as:
function(:hello,
handler: handler("hello.hande"),
runtime: :ruby
)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jets/stack/main/dsl/lambda.rb', line 21 def function(id, props={}) # Required: code, handler, role, runtime Docs: https://amzn.to/2pdot7S meth = sanitize_method_name(id) class_namespace = self.to_s.underscore.gsub('/','-') # IE: Jets::Domain => jets-domain description = "#{self.to_s} #{meth}" # not bother adding extension defaults = { code: { s3_bucket: "!Ref S3Bucket", s3_key: code_s3_key }, role: "!Ref IamRole", handler: "#{id}.lambda_handler", # default ruby convention runtime: :ruby, timeout: Jets.config.function.timeout, memory_size: Jets.config.function.memory_size, ephemeral_storage: Jets.config.function.ephemeral_storage, description: description, } function_name = "#{Jets.config.project_namespace}-#{class_namespace}-#{meth}" function_name = function_name.size > Jets::MAX_FUNCTION_NAME_SIZE ? nil : function_name defaults[:function_name] = function_name if function_name props = defaults.merge(props) props[:runtime] = Jets.ruby_runtime if props[:runtime].to_s == "ruby" props[:handler] = handler(props[:handler]) logical_id = id.to_s.gsub('/','_') resource(logical_id, "AWS::Lambda::Function", props) end |
#node_function(id, props = {}) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/jets/stack/main/dsl/lambda.rb', line 61 def node_function(id, props={}) meth = sanitize_method_name(id) props[:handler] ||= "#{meth}.handler" # default python convention props[:runtime] = "nodejs8.10" function(id, props) end |
#permission(id, props = {}) ⇒ Object
Usage:
(:my_permission, principal: "events.amazonaws.com")
72 73 74 75 76 |
# File 'lib/jets/stack/main/dsl/lambda.rb', line 72 def (id, props={}) defaults = { action: "lambda:InvokeFunction" } props = defaults.merge(props) resource(id, "AWS::Lambda::Permission", props) end |
#python_function(id, props = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/jets/stack/main/dsl/lambda.rb', line 54 def python_function(id, props={}) meth = sanitize_method_name(id) props[:handler] ||= "#{meth}.lambda_handler" # default python convention props[:runtime] = "python3.6" function(id, props) end |