Skip to content
v2.275.0

HostedZone L2 construct ​

Container for records, and records contain information about how to route traffic for a specific domain, such as example.com and its subdomains (acme.example.com, zenith.example.com).

Example ​

ts
const exampleCom = new route53.HostedZone(this, 'ExampleCom', {
  zoneName: 'example.com',
});
const exampleNet = new route53.HostedZone(this, 'ExampleNet', {
  zoneName: 'example.net',
});

const cert = new acm.Certificate(this, 'Certificate', {
  domainName: 'test.example.com',
  subjectAlternativeNames: ['cool.example.com', 'test.example.net'],
  validation: acm.CertificateValidation.fromDnsMultiZone({
    'test.example.com': exampleCom,
    'cool.example.com': exampleCom,
    'test.example.net': exampleNet,
  }),
});
python
example_com = route53.HostedZone(self, "ExampleCom",
    zone_name="example.com"
)
example_net = route53.HostedZone(self, "ExampleNet",
    zone_name="example.net"
)

cert = acm.Certificate(self, "Certificate",
    domain_name="test.example.com",
    subject_alternative_names=["cool.example.com", "test.example.net"],
    validation=acm.CertificateValidation.from_dns_multi_zone({
        "test.example.com": example_com,
        "cool.example.com": example_com,
        "test.example.net": example_net
    })
)
java
HostedZone exampleCom = HostedZone.Builder.create(this, "ExampleCom")
        .zoneName("example.com")
        .build();
HostedZone exampleNet = HostedZone.Builder.create(this, "ExampleNet")
        .zoneName("example.net")
        .build();

Certificate cert = Certificate.Builder.create(this, "Certificate")
        .domainName("test.example.com")
        .subjectAlternativeNames(List.of("cool.example.com", "test.example.net"))
        .validation(CertificateValidation.fromDnsMultiZone(Map.of(
                "test.example.com", exampleCom,
                "cool.example.com", exampleCom,
                "test.example.net", exampleNet)))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var exampleCom = new HostedZone(this, "ExampleCom", new HostedZoneProps {
    ZoneName = "example.com"
});
var exampleNet = new HostedZone(this, "ExampleNet", new HostedZoneProps {
    ZoneName = "example.net"
});

var cert = new Certificate(this, "Certificate", new CertificateProps {
    DomainName = "test.example.com",
    SubjectAlternativeNames = new [] { "cool.example.com", "test.example.net" },
    Validation = CertificateValidation.FromDnsMultiZone(new Dictionary<string, IHostedZone> {
        { "test.example.com", exampleCom },
        { "cool.example.com", exampleCom },
        { "test.example.net", exampleNet }
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
exampleCom := route53.NewHostedZone(this, jsii.String("ExampleCom"), &HostedZoneProps{
	ZoneName: jsii.String("example.com"),
})
exampleNet := route53.NewHostedZone(this, jsii.String("ExampleNet"), &HostedZoneProps{
	ZoneName: jsii.String("example.net"),
})

cert := acm.NewCertificate(this, jsii.String("Certificate"), &CertificateProps{
	DomainName: jsii.String("test.example.com"),
	SubjectAlternativeNames: []*string{
		jsii.String("cool.example.com"),
		jsii.String("test.example.net"),
	},
	Validation: acm.CertificateValidation_FromDnsMultiZone(map[string]IHostedZone{
		"test.example.com": exampleCom,
		"cool.example.com": exampleCom,
		"test.example.net": exampleNet,
	}),
})

Initializer ​

ts
new HostedZone(scope: Construct, id: string, props: HostedZoneProps)
python
HostedZone(scope: Construct, id: str, props: HostedZoneProps)
java
new HostedZone(Construct scope, String id, HostedZoneProps props)
csharp
new HostedZone(Construct scope, string id, HostedZoneProps props)
go
NewHostedZone(Scope Construct, Id *string, Props HostedZoneProps)

Construct Props ​

addTrailingDotoptionalbooleanadd_trailing_dotoptionalbooladdTrailingDotoptionalBooleanAddTrailingDotoptionalboolAddTrailingDotoptional*bool= true#
Whether to add a trailing dot to the zone name.
commentoptionalstringcommentoptionalstrcommentoptionalStringCommentoptionalstringCommentoptional*string= none#
Any comments that you want to include about the hosted zone.
queryLogsLogGroupArnoptionalstringquery_logs_log_group_arnoptionalstrqueryLogsLogGroupArnoptionalStringQueryLogsLogGroupArnoptionalstringQueryLogsLogGroupArnoptional*string= disabled#
The Amazon Resource Name (ARN) for the log group that you want Amazon Route 53 to send query logs to.
vpcsoptionalIVpc[]vpcsoptionaltyping.List[IVpc]vpcsoptionalList<IVpc>VpcsoptionalIVpc[]Vpcsoptional*[]IVpc#
A VPC that you want to associate with this hosted zone.

Default: public (no VPCs associated)

When you specify this property, a private hosted zone will be created.

You can associate additional VPCs to this private zone using addVpc(vpc).

zoneNamestringzone_namestrzoneNameStringZoneNamestringZoneName*stringrequired#
The name of the domain.

For resource record types that include a domain name, specify a fully qualified domain name.

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

Grants helper for this hosted zone.
hostedZoneArnstringhosted_zone_arnstrhostedZoneArnStringHostedZoneArnstringHostedZoneArn*string#
ARN of this hosted zone, such as arn:${Partition}:route53:::hostedzone/${Id}.
hostedZoneIdstringhosted_zone_idstrhostedZoneIdStringHostedZoneIdstringHostedZoneId*string#
ID of this hosted zone, such as "Z23ABC4XYZL05B".
hostedZoneNameServersmay be undefinedstring[]hosted_zone_name_serversmay be undefinedtyping.List[str]hostedZoneNameServersmay be undefinedList<String>HostedZoneNameServersmay be undefinedstring[]HostedZoneNameServersmay be undefined*[]*string#
Returns the set of name servers for the specific hosted zone. For example: ns1.example.com.

This attribute will be undefined for private hosted zones or hosted zones imported from another stack.

hostedZoneRefHostedZoneReferencehosted_zone_refHostedZoneReferencehostedZoneRefHostedZoneReferenceHostedZoneRefHostedZoneReferenceHostedZoneRefHostedZoneReference#
A reference to a HostedZone resource.
namestringnamestrnameStringNamestringName*string#
FQDN of this hosted zone.
nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStack#
The stack in which this resource is defined.
zoneNamestringzone_namestrzoneNameStringZoneNamestringZoneName*string#
FQDN of this hosted zone.

Methods ​

addVpc(vpc: IVpc): voiddef add_vpc(self, vpc: IVpc) -> Nonepublic void addVpc(IVpc vpc)public void AddVpc(IVpc vpc)func AddVpc(Vpc IVpc)#
Add another VPC to this private hosted zone.
1 parameter

Parameters

  • vpcvpcvpcvpcVpc — the other VPC to add.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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).

enableDnssec(options: ZoneSigningOptions): IKeySigningKeydef enable_dnssec(self, options: ZoneSigningOptions) -> IKeySigningKeypublic IKeySigningKey enableDnssec(ZoneSigningOptions options)public IKeySigningKey EnableDnssec(ZoneSigningOptions options)func EnableDnssec(Options ZoneSigningOptions) IKeySigningKey#
Enable DNSSEC for this hosted zone.

This will create a key signing key with the given options and enable DNSSEC signing for the hosted zone.

fromHostedZoneAttributes(scope: Construct, id: string, attrs: HostedZoneAttributes): IHostedZone@staticmethod def from_hosted_zone_attributes(scope: Construct, id: str, attrs: HostedZoneAttributes) -> IHostedZonepublic static IHostedZone fromHostedZoneAttributes(Construct scope, String id, HostedZoneAttributes attrs)public static IHostedZone FromHostedZoneAttributes(Construct scope, string id, HostedZoneAttributes attrs)func FromHostedZoneAttributes(Scope Construct, Id *string, Attrs HostedZoneAttributes) IHostedZonestatic#
Imports a hosted zone from another stack.

Use when both hosted zone ID and hosted zone name are known.

3 parameters

Parameters

  • scopescopescopescopeScope — the parent Construct for this Construct.
  • ididididId — the logical name of this Construct.
  • attrsattrsattrsattrsAttrs — the HostedZoneAttributes (hosted zone ID and hosted zone name).
fromHostedZoneId(scope: Construct, id: string, hostedZoneId: string): IHostedZone@staticmethod def from_hosted_zone_id(scope: Construct, id: str, hosted_zone_id: str) -> IHostedZonepublic static IHostedZone fromHostedZoneId(Construct scope, String id, String hostedZoneId)public static IHostedZone FromHostedZoneId(Construct scope, string id, string hostedZoneId)func FromHostedZoneId(Scope Construct, Id *string, HostedZoneId *string) IHostedZonestatic#
Import a Route 53 hosted zone defined either outside the CDK, or in a different CDK stack.

Use when hosted zone ID is known. If a HostedZone is imported with this method the zoneName cannot be referenced. If the zoneName is needed then the HostedZone should be imported with fromHostedZoneAttributes() or fromLookup()

3 parameters

Parameters

  • scopescopescopescopeScope — the parent Construct for this Construct.
  • ididididId — the logical name of this Construct.
  • hostedZoneIdhosted_zone_idhostedZoneIdhostedZoneIdHostedZoneId — the ID of the hosted zone to import.
fromLookup(scope: Construct, id: string, query: HostedZoneProviderProps): IHostedZone@staticmethod def from_lookup(scope: Construct, id: str, query: HostedZoneProviderProps) -> IHostedZonepublic static IHostedZone fromLookup(Construct scope, String id, HostedZoneProviderProps query)public static IHostedZone FromLookup(Construct scope, string id, HostedZoneProviderProps query)func FromLookup(Scope Construct, Id *string, Query HostedZoneProviderProps) IHostedZonestatic#
Lookup a hosted zone in the current account/region based on query parameters.

Requires environment, you must specify env for the stack.

Use to easily query hosted zones.

grantDelegation(grantee: IGrantable, options?: GrantDelegationOptions): Grantdef grant_delegation(self, grantee: IGrantable, options: typing.Optional[GrantDelegationOptions] = None) -> Grantpublic Grant grantDelegation(IGrantable grantee, GrantDelegationOptions options)public Grant GrantDelegation(IGrantable grantee, GrantDelegationOptions? options = null)func GrantDelegation(Grantee IGrantable, Options GrantDelegationOptions) Grant#
[disable-awslint:no-grants].
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.