AWS SDK for .NET
Developer Guide

Working with IAM Server Certificates

These .NET examples show you how to:

  • List server certificates

  • Get server certificates

  • Update server certificates

  • Delete server certificates

The Scenario

In these, examples, you'll basic tasks for managing server certificates for HTTPS connections. To enable HTTPS connections to your website or application on AWS, you need an SSL/TLS server certificate. To use a certificate that you obtained from an external provider with your website or application on AWS, you must upload the certificate to IAM or import it into AWS Certificate Manager.

These examples use the AWS SDK for .NET to send and receive messages by using these methods of the AmazonIdentityManagementServiceClient class:

For more information about server certificates, see Working with Server Certificates in the IAM User Guide.

List Your Server Certificates

Create an AmazonIdentityManagementServiceClient object. Next, create a ListServerCertificatesRequest object.

There are no required parameters. Call the ListServerCertificates method of the AmazonIdentityManagementServiceClient object.

public static void ListCertificates() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new ListServerCertificatesRequest(); var response = iamClient.ListServerCertificates(request); foreach (KeyValuePair<string, string> kvp in response.ResponseMetadata.Metadata) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } catch(Exception e) { Console.WriteLine(e.Message); } }

Get a Server Certificate

Create an AmazonIdentityManagementServiceClient object. Next, create a GetServerCertificateRequest object, specifying the ServerCertificateName. Call the GetServerCertificate method of the AmazonIdentityManagementServiceClient object.

public static void GetCertificate() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new GetServerCertificateRequest(); request.ServerCertificateName = "CERTIFICATE_NAME"; var response = iamClient.GetServerCertificate(request); Console.WriteLine("CertificateName = " + response.ServerCertificate.ServerCertificateMetadata.ServerCertificateName); Console.WriteLine("Certificate Arn = " + response.ServerCertificate.ServerCertificateMetadata.Arn); } catch (Exception e) { Console.WriteLine(e.Message); } }

Update a Server Certificate

Create an AmazonIdentityManagementServiceClient object. Next, create an UpdateServerCertificateRequest object, specifying the ServerCertificateName and the NewServerCertificateName. Call the UpdateServerCertificate method of the AmazonIdentityManagementServiceClient object.

public static void UpdateCertificate() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new UpdateServerCertificateRequest(); request.ServerCertificateName = "CERTIFICATE_NAME"; request.NewServerCertificateName = "NEW_Certificate_NAME"; var response = iamClient.UpdateServerCertificate(request); if (response.HttpStatusCode.ToString() == "OK") Console.WriteLine("Update succesful"); else Console.WriteLine("HTTpStatusCode returned = " + response.HttpStatusCode.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } }

Delete a Server Certificate

Create an AmazonIdentityManagementServiceClient object. Next, create a DeleteServerCertificateRequest object, specifying the ServerCertificateName. Call the DeleteServerCertificate method of the AmazonIdentityManagementServiceClient object.

public static void DeleteCertificate() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new DeleteServerCertificateRequest(); request.ServerCertificateName = "CERTIFICATE_NAME"; var response = iamClient.DeleteServerCertificate(request); if (response.HttpStatusCode.ToString() == "OK") Console.WriteLine(request.ServerCertificateName + " deleted"); else Console.WriteLine("HTTpStatusCode returned = " + response.HttpStatusCode.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } }