Class: Jets::Cfn::Builders::ApiDeploymentBuilder

Inherits:
Object
  • Object
show all
Includes:
AwsServices, Interface
Defined in:
lib/jets/cfn/builders/api_deployment_builder.rb

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #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_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #cook_template, #post_process_template, #text

Constructor Details

#initialize(options = {}) ⇒ ApiDeploymentBuilder

Returns a new instance of ApiDeploymentBuilder.



6
7
8
9
# File 'lib/jets/cfn/builders/api_deployment_builder.rb', line 6

def initialize(options={})
  @options = options
  @template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
end

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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jets/cfn/builders/api_deployment_builder.rb', line 37

def add_base_path_mapping
  return unless Jets.custom_domain?

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

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

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

#composeObject

compose is an interface method



17
18
19
20
21
22
23
24
25
26
# File 'lib/jets/cfn/builders/api_deployment_builder.rb', line 17

def compose
  return unless @options[:templates] || @options[:stack_type] != :minimal

  deployment = Jets::Resource::ApiGateway::Deployment.new
  add_resource(deployment)
  add_parameters(deployment.parameters)
  add_outputs(deployment.outputs)

  add_base_path_mapping
end

#templateObject

template is an interface method



12
13
14
# File 'lib/jets/cfn/builders/api_deployment_builder.rb', line 12

def template 
  @template
end

#template_pathObject

template_path is an interface method



54
55
56
# File 'lib/jets/cfn/builders/api_deployment_builder.rb', line 54

def template_path
  Jets::Naming.api_deployment_template_path
end

#writeObject

do not bother writing a template if routes are empty



59
60
61
# File 'lib/jets/cfn/builders/api_deployment_builder.rb', line 59

def write
  super unless Jets::Router.routes.empty?
end