Skip to content

aws-certificatemanager: Missing simple validation for domainName in the Certificate construct #35294

@slawek-amzn

Description

@slawek-amzn

Describe the bug

The Certificate construct in AWS CDK does not perform validation on the domainName property at synthesis time. If the user provides an invalid domain name (e.g., a domain that is not a valid wildcard or fully qualified domain), the error only occurs at deployment time. This results in wasted time and failed deployments. The underlying error returned by AWS Certificate Manager is:

1 validation error detected: Value of the input at 'domainValidationOptions.1.member.validationDomain' failed to satisfy constraint: Member must satisfy regular expression pattern: (\*\.)?(((?!-)[A-Za-z0-9-]{0,62}[A-Za-z0-9])\.)+((?!-)[A-Za-z0-9-]{1,62}[A-Za-z0-9]) 
(Service: AWSCertificateManager; Status Code: 400; Error Code: ValidationException)

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

The Certificate construct should validate the domainName property during synthesis. If the domain name is invalid or missing a required wildcard for subdomain coverage, CDK should raise a synthesis-time error. This prevents failed deployments and saves developer time.

Current Behavior

Currently, CDK allows invalid domain names to pass through synthesis. The errors are only caught during deployment, which leads to wasted time and failed stacks. Example:

const cert = new Certificate(this, 'InternalCert', {
  domainName: zone.zoneName, // This will fail at deployment
});

The fix that works is adding a wildcard to the domain name:

const cert = new Certificate(this, 'InternalCert', {
  domainName: `*.${zone.zoneName}`, // Passes validation
});

Reproduction Steps

N/A - every aws_cdk version

Possible Solution

Add the validation

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.207.0

AWS CDK CLI version

2.1022.0

Node.js Version

18.20.2

OS

MacOS

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-certificatemanagerRelated to Amazon Certificate ManagerbugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions