AWS SDK 또는 CLI로 UpdateServerCertificate 사용하기

AWS SDK 또는 CLI로 UpdateServerCertificate 사용하기

다음 코드 예시는 UpdateServerCertificate을(를) 사용하는 방법을 보여줘요.

출처: 문서

본문

SDK for C++

참고: GitHub에 더 많은 내용이 있어요. AWS Code Examples Repository에서 전체 예시를 찾아 실행·설정 방법을 배울 수 있어요.

bool AwsDoc::IAM::updateServerCertificate(const Aws::String &currentCertificateName,
                                          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;
}

API 상세 내용은 AWS SDK for C++ API Reference의 UpdateServerCertificate 문서를 참고하세요.

AWS CLI

AWS 계정의 서버 인증서 경로나 이름을 변경하려면

다음 update-server-certificate 명령은 인증서 이름을 myServerCertificate에서 myUpdatedServerCertificate로 바꿔요. Amazon CloudFront 서비스가 접근할 수 있도록 경로도 /cloudfront/로 변경해요. 이 명령은 출력이 없으며, 업데이트 결과는 list-server-certificates 명령으로 확인할 수 있어요.

aws-iam update-server-certificate \
    --server-certificate-name
myServerCertificate
 \
    --new-server-certificate-name
myUpdatedServerCertificate
 \
    --new-path
/cloudfront/

이 명령은 출력이 없어요.

더 자세한 내용은 AWS IAM 사용자 가이드의 'IAM 서버 인증서 관리' 문서를 참고하세요.

API 상세 내용은 AWS CLI Command Reference의 UpdateServerCertificate 문서를 참고하세요.

SDK for JavaScript (v3)

참고: GitHub에 더 많은 내용이 있어요. AWS Code Examples Repository에서 전체 예시를 찾아 실행·설정 방법을 배울 수 있어요.

서버 인증서를 업데이트해요.

import
{
 UpdateServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam";

const client = new IAMClient(
{
});

/**
 *
 * @param
{
string} currentName
 * @param
{
string} newName
 */
export const updateServerCertificate = (currentName, newName) =>
{

  const command = new UpdateServerCertificateCommand(
{

    ServerCertificateName: currentName,
    NewServerCertificateName: newName,
  });

  return client.send(command);
};

더 자세한 내용은 AWS SDK for JavaScript 개발자 가이드를 참고하세요.

API 상세 내용은 AWS SDK for JavaScript API Reference의 UpdateServerCertificate 문서를 참고하세요.

SDK for JavaScript (v2)

참고: GitHub에 더 많은 내용이 있어요. 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" });

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);
  }
});

더 자세한 내용은 AWS SDK for JavaScript 개발자 가이드를 참고하세요.

API 상세 내용은 AWS SDK for JavaScript API Reference의 UpdateServerCertificate 문서를 참고하세요.

Tools for PowerShell V4

예시 1: 이 예시는 MyServerCertificate 인증서 이름을 MyRenamedServerCertificate로 변경해요.

Update-IAMServerCertificate -ServerCertificateName MyServerCertificate -NewServerCertificateName MyRenamedServerCertificate

예시 2: 이 예시는 MyServerCertificate 인증서를 /Org1/Org2/ 경로로 옮겨요. 이로써 리소스의 ARN이 arn:aws:iam::123456789012:server-certificate/Org1/Org2/MyServerCertificate로 바뀌어요.

Update-IAMServerCertificate -ServerCertificateName MyServerCertificate -NewPath /Org1/Org2/

API 상세 내용은 AWS Tools for PowerShell Cmdlet Reference (V4)의 UpdateServerCertificate 문서를 참고하세요.

Tools for PowerShell V5

예시 1: 이 예시는 MyServerCertificate 인증서 이름을 MyRenamedServerCertificate로 변경해요.

Update-IAMServerCertificate -ServerCertificateName MyServerCertificate -NewServerCertificateName MyRenamedServerCertificate

예시 2: 이 예시는 MyServerCertificate 인증서를 /Org1/Org2/ 경로로 옮겨요. 이로써 리소스의 ARN이 arn:aws:iam::123456789012:server-certificate/Org1/Org2/MyServerCertificate로 바뀌어요.

Update-IAMServerCertificate -ServerCertificateName MyServerCertificate -NewPath /Org1/Org2/

API 상세 내용은 AWS Tools for PowerShell Cmdlet Reference (V5)의 UpdateServerCertificate 문서를 참고하세요.

SDK for Ruby

참고: GitHub에 더 많은 내용이 있어요. AWS Code Examples Repository에서 전체 예시를 찾아 실행·설정 방법을 배울 수 있어요.

서버 인증서를 나열·업데이트·삭제해요.

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 상세 내용은 AWS SDK for Ruby API Reference의 UpdateServerCertificate 문서를 참고하세요.

더 알아보기 (Learn more)