Package: aws-cdk.aws-certificatemanager
AWS Certificate Manager Construct Library---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 theMigrating to AWS CDK v2guide.AWS Certificate Manager (ACM) handles the complexity of creating, storing, and renewing public and private SSL/TLS X.509 certificates and keys that
protect your AWS websites and applications. ACM certificates can secure singular domain names, multiple specific domain names, wildcard domains, or
combinations of these. ACM wildcard certificates can protect an unlimited number of subdomains.This package provides Constructs for provisioning and referencing ACM certificates which can be used with CloudFront and ELB.After requesting a certificate, you will need to prove that you own the
domain in question before the certificate will be granted. The CloudFormation
deployment will wait until this verification process has been completed.Because of this wait time, when using manual validation methods, it's better
to provision your certificates either in a separate stack from your main
service, or provision them manually and import them into your CDK application.Note:There is a limit on total number of ACM certificates that can be requested on an account and region within a year.
The default limit is 2000, but this limit may be (much) lower on new AWS accounts.
Seehttps://docs.aws.amazon.com/acm/latest/userguide/acm-limits.htmlfor more information.DNS validationDNS validation is the preferred method to validate domain ownership, as it has a number of advantages over email validation.
See alsoValidate with DNSin the AWS Certificate Manager User Guide.If Amazon Route 53 is your DNS provider for the requested domain, the DNS record can be
created automatically:my_hosted_zone=route53.HostedZone(self,"HostedZone",zone_name="example.com")acm.Certificate(self,"Certificate",domain_name="hello.example.com",validation=acm.CertificateValidation.from_dns(my_hosted_zone))If Route 53 is not your DNS provider, the DNS records must be added manually and the stack will not complete
creating until the records are added.acm.Certificate(self,"Certificate",domain_name="hello.example.com",validation=acm.CertificateValidation.from_dns())When working with multiple domains, use theCertificateValidation.fromDnsMultiZone():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}))Email validationEmail-validated certificates (the default) are validated by receiving an
email on one of a number of predefined domains and following the instructions
in the email.SeeValidate with Emailin the AWS Certificate Manager User Guide.acm.Certificate(self,"Certificate",domain_name="hello.example.com",validation=acm.CertificateValidation.from_email())Cross-region CertificatesACM certificates that are used with CloudFront -- or higher-level constructs which rely on CloudFront -- must be in theus-east-1region.
TheDnsValidatedCertificateconstruct exists to facilitate creating these certificates cross-region. This resource can only be used with
Route53-based DNS validation.# my_hosted_zone: route53.HostedZoneacm.DnsValidatedCertificate(self,"CrossRegionCertificate",domain_name="hello.example.com",hosted_zone=my_hosted_zone,region="us-east-1")Requesting private certificatesAWS Certificate Manager can createprivate certificatesissued byPrivate Certificate Authority (PCA). Validation of private certificates is not necessary.importaws_cdk.aws_acmpcaasacmpcaacm.PrivateCertificate(self,"PrivateCertificate",domain_name="test.example.com",subject_alternative_names=["cool.example.com","test.example.net"],# optionalcertificate_authority=acmpca.CertificateAuthority.from_certificate_authority_arn(self,"CA","arn:aws:acm-pca:us-east-1:123456789012:certificate-authority/023077d8-2bfa-4eb0-8f22-05c96deade77"))ImportingIf you want to import an existing certificate, you can do so from its ARN:arn="arn:aws:..."certificate=acm.Certificate.from_certificate_arn(self,"Certificate",arn)Sharing between StacksTo share the certificate between stacks in the same CDK application, simply
pass theCertificateobject between the stacks.MetricsTheDaysToExpirymetric is available via themetricDaysToExpirymethod for
all certificates. This metric is emitted by AWS Certificates Manager once per
day until the certificate has effectively expired.An alarm can be created to determine whether a certificate is soon due for
renewal ussing the following code:importaws_cdk.aws_cloudwatchascloudwatch# my_hosted_zone: route53.HostedZonecertificate=acm.Certificate(self,"Certificate",domain_name="hello.example.com",validation=acm.CertificateValidation.from_dns(my_hosted_zone))certificate.metric_days_to_expiry().create_alarm(self,"Alarm",comparison_operator=cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,evaluation_periods=1,threshold=45)