Class: Jets::Cfn::Builder::Api::Mapping

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cfn/builder/api/mapping.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from AwsServices

#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Methods included from Interface

#add_description, #add_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #build?, #template, #text

Methods included from Util::Camelize

#camelize

Constructor Details

This class inherits a constructor from Jets::Cfn::Builder::Api::Base

Instance Method Details

#add_base_path_mappingObject

Because Jets generates a new timestamped logical id for the API Deployment resource it also creates a new root base path mapping and fails. Additionally, the base path mapping depends on the API Deploy for the stage name.

We resolve this by using a custom resource that does an in-place update.

Note, also tried to change the domain name of to something like demo-dev-.mydomain.com but that does not work because the domain name has to match the route53 record exactly.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jets/cfn/builder/api/mapping.rb', line 30

def add_base_path_mapping
  function = Jets::Cfn::Resource::ApiGateway::BasePath::Function.new
  add_resource(function)
  add_outputs(function.outputs)

  mapping = Jets::Cfn::Resource::ApiGateway::BasePath::Mapping.new
  add_resource(mapping)
  add_outputs(mapping.outputs)

  iam_role = Jets::Cfn::Resource::ApiGateway::BasePath::Role.new
  add_resource(iam_role)
  add_outputs(iam_role.outputs)
end

#composeObject

interface method



4
5
6
7
# File 'lib/jets/cfn/builder/api/mapping.rb', line 4

def compose
  add_parameters(parameters)
  add_base_path_mapping
end

#parametersObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jets/cfn/builder/api/mapping.rb', line 9

def parameters
  p = {
    GemLayer: "GemLayer",
    IamRole: "IamRole",
    RestApi: "RestApi",
    S3Bucket: "S3Bucket",
  }
  p[:DomainName] = "DomainName" if Jets.custom_domain?
  p[:BasePath] = "BasePath"
  p
end

#template_pathObject

interface method



45
46
47
# File 'lib/jets/cfn/builder/api/mapping.rb', line 45

def template_path
  Jets::Names.api_mapping_template_path
end

#writeObject

do not write a template unless custom domain is used



50
51
52
# File 'lib/jets/cfn/builder/api/mapping.rb', line 50

def write
  super if Jets.custom_domain?
end