AWS CDK AWS Certificate Manager Construct Library

1.204.0 · deprecated · verified Thu Apr 16

The `aws-cdk-aws-certificatemanager` package is a Construct Library for the AWS Cloud Development Kit (CDK) v1, providing constructs to provision and manage AWS Certificate Manager (ACM) certificates. ACM handles the complexity of creating, storing, and renewing SSL/TLS X.509 certificates for AWS services like CloudFront and Elastic Load Balancing. This package is part of the AWS CDK v1 ecosystem, which reached End-of-Support on June 1, 2023. Users are strongly encouraged to migrate to AWS CDK v2 for continued support and new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a wildcard ACM certificate using DNS validation with an existing Route 53 hosted zone. Ensure you have `aws-cdk.aws-route53` installed and `CDK_DEFAULT_ACCOUNT`, `CDK_DEFAULT_REGION`, `DOMAIN_NAME`, and `HOSTED_ZONE_ID` environment variables set. Certificates for CloudFront distributions must be provisioned in the `us-east-1` region.

import os
from aws_cdk import (
    core as cdk,
    aws_certificatemanager as acm,
    aws_route53 as route53
)

class MyCertStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Replace with your actual domain and hosted zone ID
        domain_name = os.environ.get('DOMAIN_NAME', 'example.com')
        hosted_zone_id = os.environ.get('HOSTED_ZONE_ID', 'Z1XXXXXXXXXXXXX')

        # Lookup an existing hosted zone
        # In a real application, you might create the hosted zone in the same stack or another.
        hosted_zone = route53.HostedZone.from_hosted_zone_attributes(
            self, "MyHostedZone",
            hosted_zone_id=hosted_zone_id,
            zone_name=domain_name
        )

        certificate = acm.Certificate(
            self, "MyCertificate",
            domain_name=f"*.{domain_name}",
            validation=acm.CertificateValidation.from_dns(hosted_zone),
            # For CloudFront, certificates must be in us-east-1. Specify region here if needed.
            # env=cdk.Environment(region="us-east-1")
        )

        cdk.CfnOutput(self, "CertificateArn", value=certificate.certificate_arn)

app = cdk.App()
MyCertStack(app, "CertificateStack",
            env=cdk.Environment(account=os.environ.get('CDK_DEFAULT_ACCOUNT'),
                                region=os.environ.get('CDK_DEFAULT_REGION'))
)
app.synth()

view raw JSON →