文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DeleteServerCertificate
搭配 a AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DeleteServerCertificate
。
- C++
-
- C++ 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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; }
-
如需 API 詳細資訊,請參閱 DeleteServerCertificate AWS SDK for C++ 參考中的 API。
-
- CLI
-
- AWS CLI
-
從 AWS 您的帳戶刪除伺服器憑證
下列
delete-server-certificate
命令會從 AWS 您的帳戶中移除指定的伺服器憑證。aws iam delete-server-certificate \ --server-certificate-name
myUpdatedServerCertificate
此命令不會產生輸出。
若要列出您 AWS 帳戶中可用的伺服器憑證,請使用
list-server-certificates
命令。如需詳細資訊,請參閱 IAM 使用者指南中的在 Word 中管理伺服器憑證。 AWS IAM
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteServerCertificate
。
-
- JavaScript
-
- SDK for JavaScript (v3)
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 刪除伺服器憑證。
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); };
-
如需詳細資訊,請參閱《AWS SDK for JavaScript 開發人員指南》。
-
如需 API 詳細資訊,請參閱 DeleteServerCertificate AWS SDK for JavaScript 參考中的 API。
-
- SDK for JavaScript (v2)
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 // 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); } } );
-
如需詳細資訊,請參閱《AWS SDK for JavaScript 開發人員指南》。
-
如需 API 詳細資訊,請參閱 DeleteServerCertificate AWS SDK for JavaScript 參考中的 API。
-
- PowerShell
-
- for PowerShell 工具
-
範例 1:此範例會刪除名為 的伺服器憑證
MyServerCert
。Remove-IAMServerCertificate -ServerCertificateName MyServerCert
-
如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 DeleteServerCertificate。
-
- Ruby
-
- Ruby 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 列出、更新和刪除伺服器憑證。
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
-
如需 API 詳細資訊,請參閱 DeleteServerCertificate AWS SDK for Ruby 參考中的 API。
-