AWS SDK for Java
Developer Guide

Working with IAM Server Certificates

Important

This is a preview release and is not recommended for production environments.

To enable HTTPS connections to your website or application on AWS, you need an SSL/TLS server certificate. You can use a server certificate provided by AWS Certificate Manager or one that you obtained from an external provider.

We recommend that you use ACM to provision, manage, and deploy your server certificates. With ACM you can request a certificate, deploy it to your AWS resources, and let ACM handle certificate renewals for you. Certificates provided by ACM are free. For more information about ACM , see the ACM User Guide.

Getting a Server Certificate

You can retrieve a server certificate by calling the IamClient's getServerCertificate method, passing it a GetServerCertificateRequest with the certificate's name.

Imports

import software.amazon.awssdk.services.iam.model.GetServerCertificateRequest; import software.amazon.awssdk.services.iam.model.GetServerCertificateResponse; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient;

Code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); GetServerCertificateRequest request = GetServerCertificateRequest.builder() .serverCertificateName(cert_name).build(); GetServerCertificateResponse response = iam.getServerCertificate(request);

See the complete example on GitHub.

Listing Server Certificates

To list your server certificates, call the IamClient's listServerCertificates method with a ListServerCertificatesRequest. It returns a ListServerCertificatesResponse.

Call the returned ListServerCertificateResponse object's serverCertificateMetadataList method to get a list of ServerCertificateMetadata objects that you can use to get information about each certificate.

Results may be truncated; if the ListServerCertificateResponse object's isTruncated method returns true, call the ListServerCertificatesResponse object's marker method and use the marker to create a new request. Use the new request to call listServerCertificates again to get the next batch of results.

Imports

import software.amazon.awssdk.services.iam.model.ListServerCertificatesRequest; import software.amazon.awssdk.services.iam.model.ListServerCertificatesResponse; import software.amazon.awssdk.services.iam.model.ServerCertificateMetadata; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient;

Code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); boolean done = false; String new_marker = null; while(!done) { ListServerCertificatesResponse response; if (new_marker == null) { ListServerCertificatesRequest request = ListServerCertificatesRequest.builder().build(); response = iam.listServerCertificates(request); } else { ListServerCertificatesRequest request = ListServerCertificatesRequest.builder() .marker(new_marker).build(); response = iam.listServerCertificates(request); } for(ServerCertificateMetadata metadata : response.serverCertificateMetadataList()) { System.out.printf("Retrieved server certificate %s", metadata.serverCertificateName()); } if(!response.isTruncated()) { done = true; } else { new_marker = response.marker(); } }

See the complete example on GitHub.

Updating a Server Certificate

You can update a server certificate's name or path by calling the IamClient's updateServerCertificate method. It takes a UpdateServerCertificateRequest object set with the server certificate's current name and either a new name or new path to use.

Imports

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient; import software.amazon.awssdk.services.iam.model.UpdateServerCertificateRequest; import software.amazon.awssdk.services.iam.model.UpdateServerCertificateResponse;

Code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); UpdateServerCertificateRequest request = UpdateServerCertificateRequest.builder() .serverCertificateName(cur_name) .newServerCertificateName(new_name) .build(); UpdateServerCertificateResponse response = iam.updateServerCertificate(request);

See the complete example on GitHub.

Deleting a Server Certificate

To delete a server certificate, call the IamClient's deleteServerCertificate method with a DeleteServerCertificateRequest containing the certificate's name.

Imports

import software.amazon.awssdk.services.iam.model.DeleteServerCertificateRequest; import software.amazon.awssdk.services.iam.model.DeleteServerCertificateResponse; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient;

Code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); DeleteServerCertificateRequest request = DeleteServerCertificateRequest.builder() .serverCertificateName(cert_name).build(); DeleteServerCertificateResponse response = iam.deleteServerCertificate(request);

See the complete example on GitHub.

More Information