Sha256: adad78206e64ef5da48a3c7f15fb402d379b645eb71a7ecf2b61dc39daa7d3f5

Contents?: true

Size: 1.71 KB

Versions: 15

Compression:

Stored size: 1.71 KB

Contents

# CloudFormation Docs AWS::ApiGateway::DomainName: https://amzn.to/2Bsnmbq
#
# Example:
#
#   MyDomainName:
#     Type: 'AWS::ApiGateway::DomainName'
#     Properties:
#       DomainName: api.mydomain.com
#       CertificateArn: arn:aws:acm:us-east-1:111122223333:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3
#
module Jets::Cfn::Resource::ApiGateway
  class DomainName < Jets::Cfn::Base
    def definition
      properties = {
        DomainName: domain_name,
        EndpointConfiguration: {
          Types: endpoint_types
        }
      }
      # Can really only be REGIONAL or EDGE
      if endpoint_types.include?("REGIONAL")
        properties[:RegionalCertificateArn] = cert_arn
      end
      if endpoint_types.include?("EDGE")
        properties[:CertificateArn] = cert_arn
      end

      {
        DomainName: {
          Type: "AWS::ApiGateway::DomainName",
          Properties: properties
        }
      }
    end

    def outputs
      {
        DomainName: "!Ref DomainName",
      }
    end

    def domain_name
      name = Jets.config.domain.name
      if Jets.config.domain.apex
        name ||= Jets.config.domain.hosted_zone_name
      else
        subdomain = Jets.project_namespace
        managed_domain_name = "#{subdomain}.#{Jets.config.domain.hosted_zone_name}"
        name ||= managed_domain_name
      end

      # Strip trailing period if there is one set accidentally or else get this error
      #   Trailing period should be omitted from domain name (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException
      name.sub(/\.$/,'')
    end

    def endpoint_types
      [Jets.config.domain.endpoint_type].flatten
    end

    def cert_arn
      Jets.config.domain.cert_arn
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.12 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.11 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.10 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.9 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.8 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.7 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.6 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.5 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.4 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.3 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.2 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.1 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.0 lib/jets/cfn/resource/api_gateway/domain_name.rb
jets-5.0.0.beta1 lib/jets/cfn/resource/api_gateway/domain_name.rb