

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Aggiornamento del metodo di convalida di un certificato
<a name="sdk-update"></a>

L'esempio seguente mostra come utilizzare la [ UpdateCertificateOptions ](https://docs.aws.amazon.com/acm/latest/APIReference/API_UpdateCertificateOptions.html) funzione con l'`ValidationMethod`opzione per migrare un certificato pubblico esistente convalidato via email alla convalida DNS. L'ARN del certificato viene conservato durante la migrazione. Dopo aver chiamato questa funzione, recuperate i record CNAME richiamando la [ ListCertificateDomainValidations ](https://docs.aws.amazon.com/acm/latest/APIReference/API_ListCertificateDomainValidations.html) funzione e aggiungeteli alla configurazione DNS entro 72 ore.

```
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.");
   }
}
```