Skip to main content

The CDK Construct Library for AWS::ServiceDiscovery

Project description

Amazon ECS Service Discovery Construct Library

---

End-of-Support

AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated, and users should migrate to AWS CDK v2.

For more information on how to migrate, see the Migrating to AWS CDK v2 guide.


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:

import aws_cdk.core as cdk
import aws_cdk.aws_servicediscovery as servicediscovery

app = cdk.App()
stack = cdk.Stack(app, "aws-servicediscovery-integ")

namespace = servicediscovery.HttpNamespace(stack, "MyNamespace",
    name="covfefe"
)

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

service1.register_non_ip_instance("NonIpInstance",
    custom_attributes={"arn": "arn:aws:s3:::mybucket"}
)

service2 = namespace.create_service("IpService",
    description="service registering ip instances",
    health_check=servicediscovery.HealthCheckConfig(
        type=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:

import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_elasticloadbalancingv2 as elbv2
import aws_cdk.core as cdk
import aws_cdk.aws_servicediscovery as servicediscovery

app = cdk.App()
stack = cdk.Stack(app, "aws-servicediscovery-integ")

vpc = ec2.Vpc(stack, "Vpc", max_azs=2)

namespace = servicediscovery.PrivateDnsNamespace(stack, "Namespace",
    name="boobar.com",
    vpc=vpc
)

service = namespace.create_service("Service",
    dns_record_type=servicediscovery.DnsRecordType.A_AAAA,
    dns_ttl=cdk.Duration.seconds(30),
    load_balancer=True
)

loadbalancer = elbv2.ApplicationLoadBalancer(stack, "LB", vpc=vpc, internet_facing=True)

service.register_load_balancer("Loadbalancer", loadbalancer)

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:

import aws_cdk.core as cdk
import aws_cdk.aws_servicediscovery as servicediscovery

app = cdk.App()
stack = cdk.Stack(app, "aws-servicediscovery-integ")

namespace = servicediscovery.PublicDnsNamespace(stack, "Namespace",
    name="foobar.com"
)

service = namespace.create_service("Service",
    name="foo",
    dns_record_type=servicediscovery.DnsRecordType.A,
    dns_ttl=cdk.Duration.seconds(30),
    health_check=servicediscovery.HealthCheckConfig(
        type=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:

import aws_cdk.core as cdk
import aws_cdk.aws_servicediscovery as servicediscovery

app = cdk.App()
stack = cdk.Stack(app, "aws-servicediscovery-integ")

namespace = servicediscovery.PublicDnsNamespace(stack, "Namespace",
    name="foobar.com"
)

service = namespace.create_service("Service",
    name="foo",
    dns_record_type=servicediscovery.DnsRecordType.CNAME,
    dns_ttl=cdk.Duration.seconds(30)
)

service.register_cname_instance("CnameInstance",
    instance_cname="service.pizza"
)

app.synth()

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.aws-servicediscovery-1.204.0.tar.gz (174.8 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file aws-cdk.aws-servicediscovery-1.204.0.tar.gz.

File metadata

File hashes

Hashes for aws-cdk.aws-servicediscovery-1.204.0.tar.gz
Algorithm Hash digest
SHA256 23799549fee8e71bee6cb835cacc401a6e5a31511c3acf7e07305e9c2039df2d
MD5 7d4ac4d07b9a9abe9e5470519a66a4b8
BLAKE2b-256 c3299a181cc7aa2bd13f6277ec86b424a2802299a030d9a45ce3fcb5b1be33bc

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_servicediscovery-1.204.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_cdk.aws_servicediscovery-1.204.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d2ef44db06e4a540f5279fc750ad1ce677de7fb2db40f7e666504145b4710ba
MD5 bb2eedf015b69ec849f3c4f5eced64ae
BLAKE2b-256 01ceec178d571b9c6cd6c2e5dbc609db055e51b7f91617c6dba2ba08320f14b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page