Update an IAM server certificate using an Amazon SDK
The following code examples show how to update an IAM server certificate.
- C++
-
- SDK for C++
-
Note There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. bool AwsDoc::IAM::updateServerCertificate(const Aws::String ¤tCertificateName, const Aws::String &newCertificateName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::IAM::IAMClient iam(clientConfig); Aws::IAM::Model::UpdateServerCertificateRequest request; request.SetServerCertificateName(currentCertificateName); request.SetNewServerCertificateName(newCertificateName); auto outcome = iam.UpdateServerCertificate(request); bool result = true; if (outcome.IsSuccess()) { std::cout << "Server certificate " << currentCertificateName << " successfully renamed as " << newCertificateName << std::endl; } else { if (outcome.GetError().GetErrorType() != Aws::IAM::IAMErrors::NO_SUCH_ENTITY) { std::cerr << "Error changing name of server certificate " << currentCertificateName << " to " << newCertificateName << ":" << outcome.GetError().GetMessage() << std::endl; result = false; } else { std::cout << "Certificate '" << currentCertificateName << "' not found." << std::endl; } } return result; }
-
For API details, see UpdateServerCertificate in Amazon SDK for C++ API 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 Amazon Code Examples Repository
. Create the client.
import { IAMClient } from "@aws-sdk/client-iam"; // Set the AWS Region. const REGION = "REGION"; // For example, "us-east-1". // Create an IAM service client object. const iamClient = new IAMClient({ region: REGION }); export { iamClient };
Update a server certificate.
// Import required AWS SDK clients and commands for Node.js. import { iamClient } from "./libs/iamClient.js"; import { UpdateServerCertificateCommand } from "@aws-sdk/client-iam"; // Set the parameters. export const params = { ServerCertificateName: "CERTIFICATE_NAME", //CERTIFICATE_NAME NewServerCertificateName: "NEW_CERTIFICATE_NAME", //NEW_CERTIFICATE_NAME }; export const run = async () => { try { const data = await iamClient.send( new UpdateServerCertificateCommand(params) ); console.log("Success", data); return data; } catch (err) { console.log("Error", err); } }; run();
-
For more information, see Amazon SDK for JavaScript Developer Guide.
-
For API details, see UpdateServerCertificate in Amazon 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 Amazon 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'}); var params = { ServerCertificateName: 'CERTIFICATE_NAME', NewServerCertificateName: 'NEW_CERTIFICATE_NAME' }; iam.updateServerCertificate(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });
-
For more information, see Amazon SDK for JavaScript Developer Guide.
-
For API details, see UpdateServerCertificate in Amazon SDK for JavaScript API Reference.
-
For a complete list of Amazon SDK developer guides and code examples, see Using IAM with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.