class Service (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ServiceDiscovery.Service |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsservicediscovery#Service |
Java | software.amazon.awscdk.services.servicediscovery.Service |
Python | aws_cdk.aws_servicediscovery.Service |
TypeScript (source) | aws-cdk-lib » aws_servicediscovery » Service |
Implements
IConstruct
, IDependable
, IResource
, IService
Define a CloudMap Service.
Example
import * as cdk from '../../core';
import * as servicediscovery from '../lib';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');
const namespace = new servicediscovery.PublicDnsNamespace(stack, 'Namespace', {
name: 'foobar.com',
});
const service = namespace.createService('Service', {
name: 'foo',
dnsRecordType: servicediscovery.DnsRecordType.A,
dnsTtl: cdk.Duration.seconds(30),
healthCheck: {
type: servicediscovery.HealthCheckType.HTTPS,
resourcePath: '/healthcheck',
failureThreshold: 2,
},
});
service.registerIpInstance('IpInstance', {
ipv4: '54.239.25.192',
port: 443,
});
app.synth();
Initializer
new Service(scope: Construct, id: string, props: ServiceProps)
Parameters
- scope
Construct
- id
string
- props
Service
Props
Construct Props
Name | Type | Description |
---|---|---|
namespace | INamespace | The namespace that you want to use for DNS configuration. |
custom | Health | Structure containing failure threshold for a custom health checker. |
description? | string | A description of the service. |
discovery | Discovery | Controls how instances within this service can be discovered. |
dns | Dns | The DNS type of the record that you want AWS Cloud Map to create. |
dns | Duration | The amount of time, in seconds, that you want DNS resolvers to cache the settings for this record. |
health | Health | Settings for an optional health check. |
load | boolean | Whether or not this service will have an Elastic LoadBalancer registered to it as an AliasTargetInstance. |
name? | string | A name for the Service. |
routing | Routing | The routing policy that you want to apply to all DNS records that AWS Cloud Map creates when you register an instance and specify this service. |
namespace
Type:
INamespace
The namespace that you want to use for DNS configuration.
customHealthCheck?
Type:
Health
(optional, default: none)
Structure containing failure threshold for a custom health checker.
Only one of healthCheckConfig or healthCheckCustomConfig can be specified. See: https://docs.aws.amazon.com/cloud-map/latest/api/API_HealthCheckCustomConfig.html
description?
Type:
string
(optional, default: none)
A description of the service.
discoveryType?
Type:
Discovery
(optional, default: DNS_AND_API)
Controls how instances within this service can be discovered.
dnsRecordType?
Type:
Dns
(optional, default: A)
The DNS type of the record that you want AWS Cloud Map to create.
Supported record types include A, AAAA, A and AAAA (A_AAAA), CNAME, and SRV.
dnsTtl?
Type:
Duration
(optional, default: Duration.minutes(1))
The amount of time, in seconds, that you want DNS resolvers to cache the settings for this record.
healthCheck?
Type:
Health
(optional, default: none)
Settings for an optional health check.
If you specify health check settings, AWS Cloud Map associates the health check with the records that you specify in DnsConfig. Only one of healthCheckConfig or healthCheckCustomConfig can be specified. Not valid for PrivateDnsNamespaces. If you use healthCheck, you can only register IP instances to this service.
loadBalancer?
Type:
boolean
(optional, default: false)
Whether or not this service will have an Elastic LoadBalancer registered to it as an AliasTargetInstance.
Setting this to true
correctly configures the routingPolicy
and performs some additional validation.
name?
Type:
string
(optional, default: CloudFormation-generated name)
A name for the Service.
routingPolicy?
Type:
Routing
(optional, default: WEIGHTED for CNAME records and when loadBalancer is true, MULTIVALUE otherwise)
The routing policy that you want to apply to all DNS records that AWS Cloud Map creates when you register an instance and specify this service.
Properties
Name | Type | Description |
---|---|---|
discovery | Discovery | The discovery type used by this service. |
dns | Dns | The DnsRecordType used by the service. |
env | Resource | The environment this resource belongs to. |
namespace | INamespace | The namespace for the Cloudmap Service. |
node | Node | The tree node. |
routing | Routing | The Routing Policy used by the service. |
service | string | The Arn of the namespace that you want to use for DNS configuration. |
service | string | The ID of the namespace that you want to use for DNS configuration. |
service | string | A name for the Cloudmap Service. |
stack | Stack | The stack in which this resource is defined. |
discoveryType
Type:
Discovery
The discovery type used by this service.
dnsRecordType
Type:
Dns
The DnsRecordType used by the service.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
namespace
Type:
INamespace
The namespace for the Cloudmap Service.
node
Type:
Node
The tree node.
routingPolicy
Type:
Routing
The Routing Policy used by the service.
serviceArn
Type:
string
The Arn of the namespace that you want to use for DNS configuration.
serviceId
Type:
string
The ID of the namespace that you want to use for DNS configuration.
serviceName
Type:
string
A name for the Cloudmap Service.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
register | Registers a resource that is accessible using a CNAME. |
register | Registers a resource that is accessible using an IP address. |
register | Registers an ELB as a new instance with unique name instanceId in this service. |
register | Registers a resource that is accessible using values other than an IP address or a domain name (CNAME). |
to | Returns a string representation of this construct. |
static from |
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
CnameInstance(id, props)
registerpublic registerCnameInstance(id: string, props: CnameInstanceBaseProps): IInstance
Parameters
- id
string
- props
Cname
Instance Base Props
Returns
Registers a resource that is accessible using a CNAME.
IpInstance(id, props)
registerpublic registerIpInstance(id: string, props: IpInstanceBaseProps): IInstance
Parameters
- id
string
- props
Ip
Instance Base Props
Returns
Registers a resource that is accessible using an IP address.
LoadBalancer(id, loadBalancer, customAttributes?)
registerpublic registerLoadBalancer(id: string, loadBalancer: ILoadBalancerV2, customAttributes?: { [string]: string }): IInstance
Parameters
- id
string
- loadBalancer
ILoad
Balancer V2 - customAttributes
{ [string]: string }
Returns
Registers an ELB as a new instance with unique name instanceId in this service.
NonIpInstance(id, props)
registerpublic registerNonIpInstance(id: string, props: NonIpInstanceBaseProps): IInstance
Parameters
- id
string
- props
Non
Ip Instance Base Props
Returns
Registers a resource that is accessible using values other than an IP address or a domain name (CNAME).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
ServiceAttributes(scope, id, attrs)
static frompublic static fromServiceAttributes(scope: Construct, id: string, attrs: ServiceAttributes): IService
Parameters
- scope
Construct
- id
string
- attrs
Service
Attributes
Returns