Menu
AWS Certificate Manager
User Guide (Version 1.0)

Adding Tags to a Certificate

The following example shows how to use the AddTagsToCertificate function.

Copy
package com.amazonaws.samples; import com.amazonaws.services.certificatemanager.AWSCertificateManagerClientBuilder; import com.amazonaws.services.certificatemanager.AWSCertificateManager; import com.amazonaws.services.certificatemanager.model.AddTagsToCertificateRequest; import com.amazonaws.services.certificatemanager.model.AddTagsToCertificateResult; import com.amazonaws.services.certificatemanager.model.Tag; import com.amazonaws.services.certificatemanager.model.InvalidArnException; import com.amazonaws.services.certificatemanager.model.InvalidTagException; import com.amazonaws.services.certificatemanager.model.ResourceNotFoundException; import com.amazonaws.services.certificatemanager.model.TooManyTagsException; import com.amazonaws.AmazonClientException; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.regions.Regions; import java.util.ArrayList; /** * This sample demonstrates how to use the AddTagsToCertificate function in the AWS Certificate * Manager service. * * Input parameters: * CertificateArn - The ARN of the certificate to which to add one or more tags. * Tags - An array of Tag objects to add. * */ public class AWSCertificateManagerExample { public static void main(String[] args) throws Exception { // Retrieve your credentials from the C:\Users\name\.aws\credentials file in Windows // or the ~/.aws/credentials file in Linux. AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception ex) { throw new AmazonClientException("Cannot load your credentials from file.", ex); } // Create a client. AWSCertificateManager client = AWSCertificateManagerClientBuilder.standard() .withRegion(Regions.US_EAST_1) .withCredentials(new AWSStaticCredentialsProvider(credentials)) .build(); // Create tags. Tag tag1 = new Tag(); tag1.setKey("Short_Name"); tag1.setValue("My_Cert"); Tag tag2 = new Tag() .withKey("Purpose") .withValue("Test"); // Add the tags to a collection. ArrayList<Tag> tags = new ArrayList<Tag>(); tags.add(tag1); tags.add(tag2); // Create a request object and specify the ARN of the certificate. AddTagsToCertificateRequest req = new AddTagsToCertificateRequest(); req.setCertificateArn("arn:aws:acm:region:account:certificate/12345678-1234-1234-1234-123456789012"); req.setTags(tags); // Add tags to the specified certificate. AddTagsToCertificateResult result = null; try { result = client.addTagsToCertificate(req); } catch(InvalidArnException ex) { throw ex; } catch(InvalidTagException ex) { throw ex; } catch(ResourceNotFoundException ex) { throw ex; } catch(TooManyTagsException ex) { throw ex; } // Display the result. System.out.println(result); } }