AWSCDK::ServiceDiscovery

51 types

Amazon ECS Service Discovery Construct Library

This module is part of the AWS Cloud Development Kit project.

This package contains constructs for working with AWS Cloud Map

AWS Cloud Map is a fully managed service that you can use to create and maintain a map of the backend services and resources that your applications depend on.

For further information on AWS Cloud Map, see the AWS Cloud Map documentation

HTTP Namespace Example

The following example creates an AWS Cloud Map namespace that supports API calls, creates a service in that namespace, and registers an instance to it:

require_relative '../../core'
require_relative '../lib'

app = AWSCDK::App.new
stack = AWSCDK::Stack.new(app, "aws-servicediscovery-integ")

namespace = AWSCDK::ServiceDiscovery::HttpNamespace.new(stack, "MyNamespace", {
    name: "MyHTTPNamespace",
})

service1 = namespace.create_service("NonIpService", {
    description: "service registering non-ip instances",
})

service1.register_non_ip_instance("NonIpInstance", {
    custom_attributes: {arn: "arn:aws:s3:::amzn-s3-demo-bucket"},
})

service2 = namespace.create_service("IpService", {
    description: "service registering ip instances",
    health_check: {
        type: AWSCDK::ServiceDiscovery::HealthCheckType::HTTP,
        resource_path: "/check",
    },
})

service2.register_ip_instance("IpInstance", {
    ipv4: "54.239.25.192",
})

app.synth

Private DNS Namespace Example

The following example creates an AWS Cloud Map namespace that supports both API calls and DNS queries within a vpc, creates a service in that namespace, and registers a loadbalancer as an instance.

A secondary service is also configured which only supports API based discovery, a non ip based resource is registered to this service:

require_relative '../../aws-ec2'
require_relative '../../aws-elasticloadbalancingv2'
require_relative '../../core'
require_relative '../lib'

app = AWSCDK::App.new
stack = AWSCDK::Stack.new(app, "aws-servicediscovery-integ")

vpc = AWSCDK::EC2::VPC.new(stack, "Vpc", {max_azs: 2})

namespace = AWSCDK::ServiceDiscovery::PrivateDNSNamespace.new(stack, "Namespace", {
    name: "boobar.com",
    vpc: vpc,
})

service = namespace.create_service("Service", {
    dns_record_type: AWSCDK::ServiceDiscovery::DNSRecordType::A_AAAA,
    dns_ttl: AWSCDK::Duration.seconds(30),
    load_balancer: true,
})

loadbalancer = AWSCDK::ElasticLoadBalancingv2::ApplicationLoadBalancer.new(stack, "LB", {vpc: vpc, internet_facing: true})

service.register_load_balancer("Loadbalancer", loadbalancer)

arn_service = namespace.create_service("ArnService", {
    discovery_type: AWSCDK::ServiceDiscovery::DiscoveryType::API,
})

arn_service.register_non_ip_instance("NonIpInstance", {
    custom_attributes: {arn: "arn://"},
})

app.synth

Public DNS Namespace Example

The following example creates an AWS Cloud Map namespace that supports both API calls and public DNS queries, creates a service in that namespace, and registers an IP instance:

require_relative '../../core'
require_relative '../lib'

app = AWSCDK::App.new
stack = AWSCDK::Stack.new(app, "aws-servicediscovery-integ")

namespace = AWSCDK::ServiceDiscovery::PublicDNSNamespace.new(stack, "Namespace", {
    name: "foobar.com",
})

service = namespace.create_service("Service", {
    name: "foo",
    dns_record_type: AWSCDK::ServiceDiscovery::DNSRecordType::A,
    dns_ttl: AWSCDK::Duration.seconds(30),
    health_check: {
        type: AWSCDK::ServiceDiscovery::HealthCheckType::HTTPS,
        resource_path: "/healthcheck",
        failure_threshold: 2,
    },
})

service.register_ip_instance("IpInstance", {
    ipv4: "54.239.25.192",
    port: 443,
})

app.synth

For DNS namespaces, you can also register instances to services with CNAME records:

require_relative '../../core'
require_relative '../lib'

app = AWSCDK::App.new
stack = AWSCDK::Stack.new(app, "aws-servicediscovery-integ")

namespace = AWSCDK::ServiceDiscovery::PublicDNSNamespace.new(stack, "Namespace", {
    name: "foobar.com",
})

service = namespace.create_service("Service", {
    name: "foo",
    dns_record_type: AWSCDK::ServiceDiscovery::DNSRecordType::CNAME,
    dns_ttl: AWSCDK::Duration.seconds(30),
})

service.register_cname_instance("CnameInstance", {
    instance_cname: "service.pizza",
})

app.synth

API Reference

Classes 14

AliasTargetInstanceInstance that uses Route 53 Alias record type. CfnHttpNamespaceCreates an HTTP namespace. CfnInstanceA complex type that contains information about an instance that AWS Cloud Map creates when CfnPrivateDNSNamespaceCreates a private namespace based on DNS, which is visible only inside a specified Amazon CfnPublicDNSNamespaceCreates a public namespace based on DNS, which is visible on the internet. CfnServiceA complex type that contains information about the specified service. CnameInstanceInstance that is accessible using a domain name (CNAME). HttpNamespaceDefine an HTTP Namespace. InstanceBase IPInstanceInstance that is accessible using an IP address. NonIPInstanceInstance accessible using values other than an IP address or a domain name (CNAME). PrivateDNSNamespaceDefine a Service Discovery HTTP Namespace. PublicDNSNamespaceDefine a Public DNS Namespace. ServiceDefine a CloudMap Service.

Interfaces 32

AliasTargetInstanceProps BaseInstancePropsUsed when the resource that's associated with the service instance is accessible using val BaseNamespaceProps BaseServicePropsBasic props needed to create a service in a given namespace. CfnHttpNamespacePropsProperties for defining a `CfnHttpNamespace`. CfnInstancePropsProperties for defining a `CfnInstance`. CfnPrivateDNSNamespacePropsProperties for defining a `CfnPrivateDnsNamespace`. CfnPublicDNSNamespacePropsProperties for defining a `CfnPublicDnsNamespace`. CfnServicePropsProperties for defining a `CfnService`. CnameInstanceBaseProps CnameInstanceProps DNSServicePropsService props needed to create a service in a given namespace. HealthCheckConfigSettings for an optional Amazon Route 53 health check. HealthCheckCustomConfigSpecifies information about an optional custom health check. HttpNamespaceAttributes HttpNamespaceProps IHttpNamespace IInstance INamespaceA type of namespace. IPInstanceBaseProps IPInstanceProps IPrivateDNSNamespace IPublicDNSNamespace IService NonIPInstanceBaseProps NonIPInstanceProps PrivateDNSNamespaceAttributes PrivateDNSNamespaceProps PublicDNSNamespaceAttributes PublicDNSNamespaceProps ServiceAttributes ServiceProps

Enums 5

DiscoveryTypeSpecifies information about the discovery type of a service. DNSRecordType HealthCheckType NamespaceType RoutingPolicy