Search in sources :

Example 1 with DescribeSecretRequest

use of software.amazon.awssdk.services.secretsmanager.model.DescribeSecretRequest in project aws-doc-sdk-examples by awsdocs.

the class DescribeSecret method describeGivenSecret.

// snippet-start:[secretsmanager.java2.describe_secret.main]
public static void describeGivenSecret(SecretsManagerClient secretsClient, String secretName) {
    try {
        DescribeSecretRequest secretRequest = DescribeSecretRequest.builder().secretId(secretName).build();
        DescribeSecretResponse secretResponse = secretsClient.describeSecret(secretRequest);
        Instant lastChangedDate = secretResponse.lastChangedDate();
        // Convert the Instant to readable date
        DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.US).withZone(ZoneId.systemDefault());
        formatter.format(lastChangedDate);
        System.out.println("The date of the last change to " + secretResponse.name() + " is " + lastChangedDate);
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) Instant(java.time.Instant) DescribeSecretRequest(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretRequest) DateTimeFormatter(java.time.format.DateTimeFormatter) DescribeSecretResponse(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)

Aggregations

Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 DescribeSecretRequest (software.amazon.awssdk.services.secretsmanager.model.DescribeSecretRequest)1 DescribeSecretResponse (software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)1 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)1