ACM examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with ACM.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use add-tags-to-certificate.
- AWS CLI
-
To add tags to an existing ACM Certificate
The following
add-tags-to-certificateexample adds two tags to the specified certificate. Use a space to separate multiple tags.aws acm add-tags-to-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --tagsKey=Admin,Value=AliceKey=Purpose,Value=WebsiteThis command produces no output.
For more information, see Tag AWS Certificate Manager resources
in the AWS Certificate Manager User Guide. -
For API details, see AddTagsToCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use delete-certificate.
- AWS CLI
-
To delete an ACM certificate from your account
The following
delete-certificateexample deletes the certificate with the specified ARN.aws acm delete-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111This command produces no output.
For more information, see Delete certificates managed by AWS Certificate Manager
in the AWS Certificate Manager User Guide. -
For API details, see DeleteCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use describe-certificate.
- AWS CLI
-
To retrieve the fields contained in an ACM certificate
The following
describe-certificateexample retrieves all of the fields for the certificate with the specified ARN.aws acm describe-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111Output:
{ "Certificate": { "CertificateArn": "arn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "CreatedAt": 1446835267.0, "DomainName": "www.example.com", "DomainValidationOptions": [ { "DomainName": "www.example.com", "ValidationDomain": "www.example.com", "ValidationEmails": [ "hostmaster@example.com", "admin@example.com", "owner@example.com.whoisprivacyservice.org", "tech@example.com.whoisprivacyservice.org", "admin@example.com.whoisprivacyservice.org", "postmaster@example.com", "webmaster@example.com", "administrator@example.com" ] }, { "DomainName": "www.example.net", "ValidationDomain": "www.example.net", "ValidationEmails": [ "postmaster@example.net", "admin@example.net", "owner@example.net.whoisprivacyservice.org", "tech@example.net.whoisprivacyservice.org", "admin@example.net.whoisprivacyservice.org", "hostmaster@example.net", "administrator@example.net", "webmaster@example.net" ] } ], "InUseBy": [], "IssuedAt": 1446835815.0, "Issuer": "Amazon", "KeyAlgorithm": "RSA-2048", "NotAfter": 1478433600.0, "NotBefore": 1446768000.0, "Serial": "0f:ac:b0:a3:8d:ea:65:52:2d:7d:01:3a:39:36:db:d6", "SignatureAlgorithm": "SHA256WITHRSA", "Status": "ISSUED", "Subject": "CN=www.example.com", "SubjectAlternativeNames": [ "www.example.com", "www.example.net" ] } }For more information, see View AWS Certificate Manager certificate details
in the AWS Certificate Manager User Guide. -
For API details, see DescribeCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use export-certificate.
- AWS CLI
-
To export a private certificate issued by a private CA.
The following
export-certificateexample exports a private certificate, certificate chain, and private key to your display.aws acm export-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --passphrasefile://path-to-passphrase-fileContents of
path-to-passphrase-file:examplePassphrase123Output:
{ "Certificate": "-----BEGIN CERTIFICATE-----\nMIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC\nVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6\nNYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE=\n-----END CERTIFICATE-----\n", "CertificateChain": "-----BEGIN CERTIFICATE-----\nMIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC\nb24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAd\nNYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE=\n-----END CERTIFICATE-----\n", "PrivateKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIIFHzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIEXAMPLEKEYAgIIADAd\nBglghkgBZQMEASoEEEXAMPLEPRIVATEKEYEXAMPLEEXAMPLE=\n-----END ENCRYPTED PRIVATE KEY-----\n" }To export the certificate, chain, and private key to a local file, use the following command.
aws acm export-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --passphrasefile://path-to-passphrase-file>c:\temp\export.txtFor more information, see Export an AWS Certificate Manager private certificate
in the AWS Certificate Manager User Guide. -
For API details, see ExportCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use get-certificate.
- AWS CLI
-
To retrieve an ACM certificate
The following
get-certificateexample retrieves the certificate for the specified ARN and the certificate chain.aws acm get-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111Output:
{ "Certificate": "-----BEGIN CERTIFICATE-----\nMIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC\nVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6\nb24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAd\nBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcNMTEwNDI1MjA0NTIxWhcN\nMTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYD\nVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25z\nb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGF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l0ZxBHjJnyp378OD8uTs7fLvjx79LjSTb\nNYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE=\n-----END CERTIFICATE-----\n" }For more information, see View AWS Certificate Manager certificate details
in the AWS Certificate Manager User Guide. -
For API details, see GetCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use import-certificate.
- AWS CLI
-
To import a certificate into ACM.
The following
import-certificateexample imports a certificate into ACM. Replace the file names with your own.aws acm import-certificate \ --certificatefile://Certificate.pem\ --certificate-chainfile://CertificateChain.pem\ --private-keyfile://PrivateKey.pemContents of
Certificate.pem:-----BEGIN CERTIFICATE----- EXAMPLECERTIFICATEDATA... -----END CERTIFICATE-----Contents of
CertificateChain.pem:-----BEGIN CERTIFICATE----- EXAMPLEINTERMEDIATECERTIFICATEDATA... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- EXAMPLEROOTCERTIFICATEDATA... -----END CERTIFICATE-----Contents of
PrivateKey.pem:-----BEGIN PRIVATE KEY----- EXAMPLEPRIVATEKEYDATA... -----END PRIVATE KEY-----Output:
{ "CertificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }For more information, see Import certificates into AWS Certificate Manager
in the AWS Certificate Manager User Guide. -
For API details, see ImportCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use list-certificates.
- AWS CLI
-
To list the ACM certificates for an AWS account
The following
list-certificatesexample lists the ARNs of the certificates in your account.aws acm list-certificatesOutput:
{ "CertificateSummaryList": [ { "CertificateArn": "arn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "DomainName": "www.example.com" }, { "CertificateArn": "arn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "DomainName": "www.example.net" } ] }You can decide how many certificates you want to display each time you call
list-certificates. For example, if you have four certificates and you want to display no more than two at a time, set themax-itemsargument to 2 as in the following example.aws acm list-certificates \ --max-items2Two certificate ARNs and a
NextTokenvalue are displayed.Output:
{ "CertificateSummaryList": [ { "CertificateArn": "arn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "DomainName": "www.example.com" }, { "CertificateArn": "arn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "DomainName": "www.example.net" } ], "NextToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333" }To display the next two certificates in your account, set this
NextTokenvalue in your next call.aws acm list-certificates \ --max-items2\ --next-tokena1b2c3d4-5678-90ab-cdef-EXAMPLE33333You can filter your output by using the
certificate-statusesargument. The following command displays certificates that have a PENDING_VALIDATION status.aws acm list-certificates \ --certificate-statusesPENDING_VALIDATIONYou can also filter your output by using the
includesargument. The following command displays certificates filtered on the following properties. The certificates to be displayed:Specify that the RSA algorithm and a 2048 bit key are used to generate key pairs.Contain a Key Usage extension that specifies that the certificates can be used to create digital signatures.Contain an Extended Key Usage extension that specifies that the certificates can be used for code signing.
To display the certificates that have these properties, use the following command.
aws acm list-certificates \ --max-items10\ --includesextendedKeyUsage=CODE_SIGNING,keyUsage=DIGITAL_SIGNATURE,keyTypes=RSA_2048For more information, see Search certificates managed by AWS Certificate Manager
in the AWS Certificate Manager User Guide. -
For API details, see ListCertificates
in AWS CLI Command Reference.
-
The following code example shows how to use list-tags-for-certificate.
- AWS CLI
-
To list the tags applied to an ACM Certificate
The following
list-tags-for-certificateexample lists the tags applied to a certificate in your account.aws acm list-tags-for-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111Output:
{ "Tags": [ { "Value": "Website", "Key": "Purpose" }, { "Value": "Alice", "Key": "Admin" } ] }For more information, see Tag AWS Certificate Manager resources
in the AWS Certificate Manager User Guide. -
For API details, see ListTagsForCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use remove-tags-from-certificate.
- AWS CLI
-
To remove a tag from an ACM Certificate
The following
remove-tags-from-certificateexample removes two tags from the specified certificate. Use a space to separate multiple tags.aws acm remove-tags-from-certificate \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --tagsKey=Admin,Value=AliceKey=Purpose,Value=WebsiteThis command produces no output.
For more information, see Tag AWS Certificate Manager resources
in the AWS Certificate Manager User Guide. -
For API details, see RemoveTagsFromCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use request-certificate.
- AWS CLI
-
To request a new ACM certificate
The following
request-certificateexample requests a new certificate for the www.example.com domain using DNS validation.aws acm request-certificate \ --domain-namewww.example.com\ --validation-methodDNSOutput:
{ "CertificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }You can enter an idempotency token to distinguish between calls to
request-certificate.aws acm request-certificate \ --domain-namewww.example.com\ --validation-methodDNS\ --idempotency-token91adc45qYou can enter one or more subject alternative names to request a certificate that will protect more than one apex domain.
aws acm request-certificate \ --domain-nameexample.com\ --validation-methodDNS\ --idempotency-token91adc45q\ --subject-alternative-nameswww.example.netYou can enter an alternative name that can also be used to reach your website.
aws acm request-certificate \ --domain-nameexample.com\ --validation-methodDNS\ --idempotency-token91adc45q\ --subject-alternative-nameswww.example.comYou can use an asterisk (*) as a wildcard to create a certificate for several subdomains in the same domain.
aws acm request-certificate \ --domain-nameexample.com\ --validation-methodDNS\ --idempotency-token91adc45q\ --subject-alternative-names*.example.comYou can also enter multiple alternative names.
aws acm request-certificate \ --domain-nameexample.com\ --validation-methodDNS\ --subject-alternative-namesb.example.comc.example.comd.example.comIf you are using email for validation, you can enter domain validation options to specify the domain to which the validation email will be sent.
aws acm request-certificate \ --domain-nameexample.com\ --validation-methodEMAIL\ --subject-alternative-nameswww.example.com\ --domain-validation-optionsDomainName=example.com,ValidationDomain=example.comThe following command opts out of certificate transparency logging when you request a new certificate.
aws acm request-certificate \ --domain-namewww.example.com\ --validation-methodDNS\ --optionsCertificateTransparencyLoggingPreference=DISABLED\ --idempotency-token184627For more information, see AWS Certificate Manager public certificates
in the AWS Certificate Manager User Guide. -
For API details, see RequestCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use resend-validation-email.
- AWS CLI
-
To resend validation email for your ACM certificate request
The following
resend-validation-emailexample tells the Amazon certificate authority to send validation email to the appropriate addresses.aws acm resend-validation-email \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --domainwww.example.com\ --validation-domainexample.comThis command produces no output.
For more information, see AWS Certificate Manager email validation
in the AWS Certificate Manager User Guide. -
For API details, see ResendValidationEmail
in AWS CLI Command Reference.
-
The following code example shows how to use update-certificate-options.
- AWS CLI
-
To update the certificate options
The following
update-certificate-optionsexample opts out of certificate transparency logging.aws acm update-certificate-options \ --certificate-arnarn:aws:acm:region:account:certificate/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --optionsCertificateTransparencyLoggingPreference=DISABLEDThis command produces no output.
For more information, see Certificate Transparency Logging
in the AWS Certificate Manager User Guide. -
For API details, see UpdateCertificateOptions
in AWS CLI Command Reference.
-