Searching the certificate inventory - AWS Certificate Manager
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Searching the certificate inventory

The following Java code example shows how to use the SearchInventory operation to find imported certificates that aren't in use, soonest to expire first. For more information, see Search and investigate inventory certificates.

package com.amazonaws.samples; import com.amazonaws.services.certificatemanager.AWSCertificateManagerClientBuilder; import com.amazonaws.services.certificatemanager.AWSCertificateManager; import com.amazonaws.services.certificatemanager.model.InventoryFilterPredicate; import com.amazonaws.services.certificatemanager.model.InventoryFilterStatement; import com.amazonaws.services.certificatemanager.model.SearchInventoryRequest; import com.amazonaws.services.certificatemanager.model.SearchInventoryResult; import com.amazonaws.services.certificatemanager.model.AWSCertificateManagerException; public class AWSCertificateManagerSample { public static void main(String[] args) { // Send requests to your organization's home Region. AWSCertificateManager client = AWSCertificateManagerClientBuilder.standard() .withRegion("us-east-1") .build(); // Match imported certificates that aren't in use. InventoryFilterStatement filter = new InventoryFilterStatement() .withAnd( new InventoryFilterStatement().withFilter( new InventoryFilterPredicate().withIssuanceType("IMPORTED")), new InventoryFilterStatement().withFilter( new InventoryFilterPredicate().withUsageStatus("NOT_IN_USE"))); // Create the request. SearchInventoryRequest req = new SearchInventoryRequest() .withFilter(filter) .withSortBy("NOT_AFTER") .withSortOrder("ASCENDING") .withMaxResults(25); // Search the inventory. try { SearchInventoryResult result = client.searchInventory(req); System.out.println(result.getTotalCount()); System.out.println(result.getCertificates()); } catch (AWSCertificateManagerException e) { System.err.println("Failed to search the inventory: " + e.getMessage()); } } }