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);
}
}
Aggregations