View a markdown version of this page

Mettre à jour la méthode de validation d'un certificat - AWS Gestionnaire de certificats

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Mettre à jour la méthode de validation d'un certificat

L'exemple suivant montre comment utiliser la UpdateCertificateOptions fonction avec l'ValidationMethodoption permettant de migrer un certificat public validé par e-mail existant vers la validation DNS. L'ARN du certificat est préservé pendant la migration. Après avoir appelé cette fonction, récupérez les enregistrements CNAME en appelant la ListCertificateDomainValidations fonction et ajoutez-les à votre configuration DNS dans les 72 heures.

package com.amazonaws.samples; import com.amazonaws.AmazonClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.regions.Regions; import com.amazonaws.services.certificatemanager.AWSCertificateManagerClientBuilder; import com.amazonaws.services.certificatemanager.AWSCertificateManager; import com.amazonaws.services.certificatemanager.model.CertificateOptions; import com.amazonaws.services.certificatemanager.model.UpdateCertificateOptionsRequest; import com.amazonaws.services.certificatemanager.model.UpdateCertificateOptionsResult; import com.amazonaws.services.certificatemanager.model.ConflictException; import com.amazonaws.services.certificatemanager.model.InvalidArnException; import com.amazonaws.services.certificatemanager.model.InvalidStateException; import com.amazonaws.services.certificatemanager.model.LimitExceededException; import com.amazonaws.services.certificatemanager.model.ResourceNotFoundException; import com.amazonaws.services.certificatemanager.model.ValidationException; public class UpdateCertificateOptions { 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 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.your_region) .withCredentials(new AWSStaticCredentialsProvider(credentials)) .build(); // Build a CertificateOptions with ValidationMethod set to DNS, then create the // request. The certificate must be an issued public certificate that uses email // validation. CertificateOptions options = new CertificateOptions() .withValidationMethod("DNS"); UpdateCertificateOptionsRequest req = new UpdateCertificateOptionsRequest() .withCertificateArn("arn:aws:acm:region:account:" + "certificate/12345678-1234-1234-1234-123456789012") .withOptions(options); // Initiate the migration. UpdateCertificateOptionsResult result = null; try { result = client.updateCertificateOptions(req); } catch (ValidationException ex) { // Thrown when the certificate is not an issued public certificate, // or when the requested migration path is not supported (for example, // DNS to email). throw ex; } catch (ConflictException ex) { // Thrown when a migration is already in progress for this certificate. throw ex; } catch (InvalidArnException ex) { throw ex; } catch (InvalidStateException ex) { throw ex; } catch (LimitExceededException ex) { throw ex; } catch (ResourceNotFoundException ex) { throw ex; } // The response is empty on success. After this call returns, retrieve the CNAME // records by calling ListCertificateDomainValidations and add them to your DNS // configuration within 72 hours. System.out.println("Migration initiated. Retrieve CNAME records with " + "ListCertificateDomainValidations."); } }