Use AddTagsToCertificate with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use AddTagsToCertificate with an AWS SDK or CLI

The following code examples show how to use AddTagsToCertificate.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

//! Add tags to an AWS Certificate Manager (ACM) certificate. /*! \param certificateArn: The Amazon Resource Name (ARN) of a certificate. \param tagKey: The key for the tag. \param tagValue: The value for the tag. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::ACM::addTagsToCertificate(const Aws::String &certificateArn, const Aws::String &tagKey, const Aws::String &tagValue, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::ACM::ACMClient acmClient(clientConfiguration); Aws::ACM::Model::AddTagsToCertificateRequest request; Aws::Vector<Aws::ACM::Model::Tag> tags; Aws::ACM::Model::Tag tag; tag.WithKey(tagKey).WithValue(tagValue); tags.push_back(tag); request.WithCertificateArn(certificateArn).WithTags(tags); Aws::ACM::Model::AddTagsToCertificateOutcome outcome = acmClient.AddTagsToCertificate(request); if (!outcome.IsSuccess()) { std::cerr << "Error: addTagsToCertificate: " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Success: Tag with key '" << tagKey << "' and value '" << tagValue << "' added to certificate with ARN '" << certificateArn << "'." << std::endl; } return outcome.IsSuccess(); }
CLI
AWS CLI

To add tags to an existing ACM Certificate

The following add-tags-to-certificate command adds two tags to the specified certificate. Use a space to separate multiple tags:

aws acm add-tags-to-certificate --certificate-arn arn:aws:acm:region:account:certificate/12345678-1234-1234-1234-123456789012 --tags Key=Admin,Value=Alice Key=Purpose,Value=Website
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Before running this Java V2 code example, set up your development * environment, including your credentials. * <p> * For more information, see the following documentation topic: * <p> * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class AddTagsToCertificate { public static void main(String[] args) { final String usage = """ Usage: <certArn> Where: certArn - the ARN of the certificate. """; if (args.length != 1) { System.out.println(usage); return; } String certArn = args[0]; addTags(certArn); } /** * Adds tags to a certificate in AWS Certificate Manager (ACM). * * @param certArn the Amazon Resource Name (ARN) of the certificate to add tags to */ public static void addTags(String certArn) { AcmClient acmClient = AcmClient.create(); List<Tag> expectedTags = List.of(Tag.builder().key("key").value("value").build()); AddTagsToCertificateRequest addTagsToCertificateRequest = AddTagsToCertificateRequest.builder() .certificateArn(certArn) .tags(expectedTags) .build(); try { acmClient.addTagsToCertificate(addTagsToCertificateRequest); System.out.println("Successfully added tags to a certificate"); } catch (AcmException e) { System.out.println(e.getMessage()); } } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class AcmCertificate: """ Encapsulates ACM functions. """ def __init__(self, acm_client): """ :param acm_client: A Boto3 ACM client. """ self.acm_client = acm_client def add_tags(self, certificate_arn, tags): """ Adds tags to a certificate. Tags are key-value pairs that contain custom metadata. :param certificate_arn: The ARN of the certificate. :param tags: A dictionary of key-value tags to add to the certificate. """ try: self.acm_client.add_tags_to_certificate( CertificateArn=certificate_arn, Tags=[{"Key": key, "Value": value} for key, value in tags.items()], ) logger.info("Added %s tags to certificate %s.", len(tags), certificate_arn) except ClientError: logger.exception("Couldn't add tags to certificate %s.", certificate_arn) raise