There are more AWS SDK examples available in the AWS Doc SDK Examples
Use DeleteServerCertificate
with an AWS SDK or CLI
The following code examples show how to use DeleteServerCertificate
.
- C++
-
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. bool AwsDoc::IAM::deleteServerCertificate(const Aws::String &certificateName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::IAM::IAMClient iam(clientConfig); Aws::IAM::Model::DeleteServerCertificateRequest request; request.SetServerCertificateName(certificateName); const auto outcome = iam.DeleteServerCertificate(request); bool result = true; if (!outcome.IsSuccess()) { if (outcome.GetError().GetErrorType() != Aws::IAM::IAMErrors::NO_SUCH_ENTITY) { std::cerr << "Error deleting server certificate " << certificateName << ": " << outcome.GetError().GetMessage() << std::endl; result = false; } else { std::cout << "Certificate '" << certificateName << "' not found." << std::endl; } } else { std::cout << "Successfully deleted server certificate " << certificateName << std::endl; } return result; }
-
For API details, see DeleteServerCertificate in AWS SDK for C++ API Reference.
-
- CLI
-
- AWS CLI
-
To delete a server certificate from your AWS account
The following
delete-server-certificate
command removes the specified server certificate from your AWS account.aws iam delete-server-certificate \ --server-certificate-name
myUpdatedServerCertificate
This command produces no output.
To list the server certificates available in your AWS account, use the
list-server-certificates
command.For more information, see Managing server certificates in IAM in the AWS IAM User Guide.
-
For API details, see DeleteServerCertificate
in AWS CLI Command Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Delete a server certificate.
import { DeleteServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam"; const client = new IAMClient({}); /** * * @param {string} certName */ export const deleteServerCertificate = (certName) => { const command = new DeleteServerCertificateCommand({ ServerCertificateName: certName, }); return client.send(command); };
-
For more information, see AWS SDK for JavaScript Developer Guide.
-
For API details, see DeleteServerCertificate in AWS SDK for JavaScript API Reference.
-
- SDK for JavaScript (v2)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. // Load the AWS SDK for Node.js var AWS = require("aws-sdk"); // Set the region AWS.config.update({ region: "REGION" }); // Create the IAM service object var iam = new AWS.IAM({ apiVersion: "2010-05-08" }); iam.deleteServerCertificate( { ServerCertificateName: "CERTIFICATE_NAME" }, function (err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } } );
-
For more information, see AWS SDK for JavaScript Developer Guide.
-
For API details, see DeleteServerCertificate in AWS SDK for JavaScript API Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example deletes the server certificate named
MyServerCert
.Remove-IAMServerCertificate -ServerCertificateName MyServerCert
-
For API details, see DeleteServerCertificate in AWS Tools for PowerShell Cmdlet Reference.
-
- Ruby
-
- SDK for Ruby
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. List, update, and delete server certificates.
class ServerCertificateManager def initialize(iam_client, logger: Logger.new($stdout)) @iam_client = iam_client @logger = logger @logger.progname = "ServerCertificateManager" end # Creates a new server certificate. # @param name [String] the name of the server certificate # @param certificate_body [String] the contents of the certificate # @param private_key [String] the private key contents # @return [Boolean] returns true if the certificate was successfully created def create_server_certificate(name, certificate_body, private_key) @iam_client.upload_server_certificate({ server_certificate_name: name, certificate_body: certificate_body, private_key: private_key, }) true rescue Aws::IAM::Errors::ServiceError => e puts "Failed to create server certificate: #{e.message}" false end # Lists available server certificate names. def list_server_certificate_names response = @iam_client.list_server_certificates if response.server_certificate_metadata_list.empty? @logger.info("No server certificates found.") return end response.server_certificate_metadata_list.each do |certificate_metadata| @logger.info("Certificate Name: #{certificate_metadata.server_certificate_name}") end rescue Aws::IAM::Errors::ServiceError => e @logger.error("Error listing server certificates: #{e.message}") end # Updates the name of a server certificate. def update_server_certificate_name(current_name, new_name) @iam_client.update_server_certificate( server_certificate_name: current_name, new_server_certificate_name: new_name ) @logger.info("Server certificate name updated from '#{current_name}' to '#{new_name}'.") true rescue Aws::IAM::Errors::ServiceError => e @logger.error("Error updating server certificate name: #{e.message}") false end # Deletes a server certificate. def delete_server_certificate(name) @iam_client.delete_server_certificate(server_certificate_name: name) @logger.info("Server certificate '#{name}' deleted.") true rescue Aws::IAM::Errors::ServiceError => e @logger.error("Error deleting server certificate: #{e.message}") false end end
-
For API details, see DeleteServerCertificate in AWS SDK for Ruby API Reference.
-