Class: Jets::Cfn::Resource::ApiGateway::BasePath::Function

Inherits:
Base
  • Object
show all
Includes:
Lambda::Function::Environment
Defined in:
lib/jets/cfn/resource/api_gateway/base_path/function.rb

Instance Method Summary collapse

Methods included from Lambda::Function::Environment

#env_properties, #environment, #jets_env

Methods inherited from Base

#attributes, #logical_id, #outputs, #parameters, #permission, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type

Methods included from Util::Camelize

#camelize

Instance Method Details

#code_s3_keyObject



52
53
54
55
# File 'lib/jets/cfn/resource/api_gateway/base_path/function.rb', line 52

def code_s3_key
  checksum = Jets::Builders::Md5.checksums["stage/code"]
  "jets/code/code-#{checksum}.zip" # s3_key
end

#definitionObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jets/cfn/resource/api_gateway/base_path/function.rb', line 5

def definition
  {
    BasePathFunction: {
      Type: "AWS::Lambda::Function",
      Properties: {
        FunctionName: function_name,
        Description: "Jets#base_path",
        Code: {
          S3Bucket: "!Ref S3Bucket",
          S3Key: code_s3_key,
        },
        Role: "!GetAtt BasePathRole.Arn",
        Handler: handler,
        Runtime: get_runtime,
        Timeout: 60,
        MemorySize: 1536,
        Environment: env_properties[:Environment],
        Layers: layers,
      }
    }
  }
end

#function_nameObject

JETS_RESET is respected here because CloudFormation Custom Resources do not allow updates to the ServiceToken property. Changing the base-path Lambda Function name results in a CloudFormation error:

Modifying service token is not allowed


44
45
46
# File 'lib/jets/cfn/resource/api_gateway/base_path/function.rb', line 44

def function_name
  "#{Jets.project_namespace}-jets-base-path"
end

#get_runtimeObject



28
29
30
31
# File 'lib/jets/cfn/resource/api_gateway/base_path/function.rb', line 28

def get_runtime
  props = camelize(Jets.application.config.function.to_h)
  props[:Runtime] || Jets.ruby_runtime
end

#handlerObject



48
49
50
# File 'lib/jets/cfn/resource/api_gateway/base_path/function.rb', line 48

def handler
  "handlers/functions/jets/base_path.lambda_handler"
end

#layersObject



33
34
35
36
# File 'lib/jets/cfn/resource/api_gateway/base_path/function.rb', line 33

def layers
  return Jets.config.lambda.layers if Jets.config.pro.disable
  ["!Ref GemLayer"] + Jets.config.lambda.layers
end