Sha256: a24e4aee95bbe3a96c45e8f98545127dea0d51b2bbd714c3421e969978e73354

Contents?: true

Size: 1.93 KB

Versions: 32

Compression:

Stored size: 1.93 KB

Contents

module Jets::Stack::Main::Dsl
  module Lambda
    # 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
    #   )
    #
    def function(id, props={})
      # Required: code, handler, role, runtime Docs: https://amzn.to/2pdot7S
      meth = id.to_s.underscore
      defaults = {
        function_name: "#{Jets.config.project_namespace}-#{id.to_s.underscore}",
        code: {
          s3_bucket: "!Ref S3Bucket",
          s3_key: code_s3_key
        },
        role: "!Ref IamRole",
        handler: "#{meth}.handle", # default ruby convention
        runtime: :ruby,
        timeout: Jets.config.function.timeout,
        memory_size: Jets.config.function.memory_size,
      }
      props = defaults.merge(props)
      props[:runtime] = "nodejs8.10" if props[:runtime].to_s == "ruby"
      props[:handler] = handler(props[:handler])

      resource(id, "AWS::Lambda::Function", props)
    end
    alias_method :ruby_function, :function
    alias_method :lambda_function, :function

    def python_function(id, props={})
      meth = id.to_s.underscore
      props[:handler] ||= "#{meth}.lambda_handler" # default python convention
      props[:runtime] = "python3.6"
      function(id, props)
    end

    def node_function(id, props={})
      meth = id.to_s.underscore
      props[:handler] ||= "#{meth}.handler" # default python convention
      props[:runtime] = "node8.10"
      function(id, props)
    end

    # Usage:
    #
    #   permission(:my_permission, principal: "events.amazonaws.com")
    #
    def permission(id, props={})
      defaults = { action: "lambda:InvokeFunction" }
      props = defaults.merge(props)
      resource(id, "AWS::Lambda::Permission", props)
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
jets-1.1.5 lib/jets/stack/main/extensions/lambda.rb
jets-1.1.4 lib/jets/stack/main/extensions/lambda.rb
jets-1.1.3 lib/jets/stack/main/extensions/lambda.rb
jets-1.1.2 lib/jets/stack/main/extensions/lambda.rb
jets-1.1.1 lib/jets/stack/main/extensions/lambda.rb
jets-1.1.0 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.18 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.17 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.16 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.15 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.13 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.12 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.11 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.10 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.9 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.8 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.7 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.6 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.5 lib/jets/stack/main/extensions/lambda.rb
jets-1.0.4 lib/jets/stack/main/extensions/lambda.rb