다음과 CreateAlias 함께 사용 AWS SDK또는 CLI - AWS Key Management Service

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

다음과 CreateAlias 함께 사용 AWS SDK또는 CLI

다음 코드 예제는 CreateAlias의 사용 방법을 보여 줍니다.

.NET
AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

using System; using System.Threading.Tasks; using Amazon.KeyManagementService; using Amazon.KeyManagementService.Model; /// <summary> /// Creates an alias for an AWS Key Management Service (AWS KMS) key. /// </summary> public class CreateAlias { public static async Task Main() { var client = new AmazonKeyManagementServiceClient(); // The alias name must start with alias/ and can be // up to 256 alphanumeric characters long. var aliasName = "alias/ExampleAlias"; // The value supplied as the TargetKeyId can be either // the key ID or key Amazon Resource Name (ARN) of the // AWS KMS key. var keyId = "1234abcd-12ab-34cd-56ef-1234567890ab"; var request = new CreateAliasRequest { AliasName = aliasName, TargetKeyId = keyId, }; var response = await client.CreateAliasAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Alias, {aliasName}, successfully created."); } else { Console.WriteLine($"Could not create alias."); } } }
  • 자세한 API 내용은 CreateAlias을 참조하십시오. AWS SDK for .NET API참조.

CLI
AWS CLI

키의 별칭을 만들려면 KMS

다음 create-alias 명령은 KMS 키 ID로 식별되는 키의 이름을 딴 example-alias 별칭을 만듭니다. 1234abcd-12ab-34cd-56ef-1234567890ab

별칭 이름은 alias/로 시작해야 합니다. 로 시작하는 별칭 이름은 사용하지 마십시오alias/aws. 별칭은 에서 사용하도록 예약되어 있습니다. AWS.

aws kms create-alias \ --alias-name alias/example-alias \ --target-key-id 1234abcd-12ab-34cd-56ef-1234567890ab

이 명령은 출력을 반환하지 않습니다. 새 별칭을 보려면 list-aliases 명령을 사용하세요.

자세한 내용은 별칭 사용을 참조하십시오. AWS 키 관리 서비스 개발자 가이드.

  • 자세한 API 내용은 CreateAlias을 참조하십시오. AWS CLI 명령 레퍼런스.

Java
SDK자바 2.x의 경우
참고

더 많은 내용이 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

/** * Creates a custom alias for the specified target key asynchronously. * * @param targetKeyId the ID of the target key for the alias * @param aliasName the name of the alias to create * @return a {@link CompletableFuture} that completes when the alias creation operation is finished */ public CompletableFuture<Void> createCustomAliasAsync(String targetKeyId, String aliasName) { CreateAliasRequest aliasRequest = CreateAliasRequest.builder() .aliasName(aliasName) .targetKeyId(targetKeyId) .build(); CompletableFuture<CreateAliasResponse> responseFuture = getAsyncClient().createAlias(aliasRequest); responseFuture.whenComplete((response, exception) -> { if (exception == null) { logger.info("{} was successfully created.", aliasName); } else { if (exception instanceof ResourceExistsException) { logger.info("Alias [{}] already exists. Moving on...", aliasName); } else if (exception instanceof KmsException kmsEx) { throw new RuntimeException("KMS error occurred while creating alias: " + kmsEx.getMessage(), kmsEx); } else { throw new RuntimeException("An unexpected error occurred while creating alias: " + exception.getMessage(), exception); } } }); return responseFuture.thenApply(response -> null); }
  • 자세한 API 내용은 CreateAlias을 참조하십시오. AWS SDK for Java 2.x API참조.

Kotlin
SDK코틀린의 경우
참고

더 많은 정보가 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

suspend fun createCustomAlias( targetKeyIdVal: String?, aliasNameVal: String?, ) { val request = CreateAliasRequest { aliasName = aliasNameVal targetKeyId = targetKeyIdVal } KmsClient { region = "us-west-2" }.use { kmsClient -> kmsClient.createAlias(request) println("$aliasNameVal was successfully created") } }
  • 자세한 API 내용은 CreateAlias을 참조하십시오. AWS SDKKotlin API 레퍼런스는 여기를 참조하세요.

Python
SDK파이썬용 (보토3)
참고

더 많은 정보가 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

class AliasManager: def __init__(self, kms_client): self.kms_client = kms_client self.created_key = None def create_alias(self, key_id): """ Creates an alias for the specified key. :param key_id: The ARN or ID of a key to give an alias. :return: The alias given to the key. """ alias = "" while alias == "": alias = input(f"What alias would you like to give to key {key_id}? ") try: self.kms_client.create_alias(AliasName=alias, TargetKeyId=key_id) except ClientError as err: logger.error( "Couldn't create alias %s. Here's why: %s", alias, err.response["Error"]["Message"], ) else: print(f"Created alias {alias} for key {key_id}.") return alias
  • 자세한 API 내용은 CreateAlias을 참조하십시오. AWS SDK파이썬 (Boto3) API 참조용.

전체 목록은 다음과 같습니다. AWS SDK개발자 가이드 및 코드 예제는 을 참조하십시오사용 AWS KMS 와 함께 AWS SDK. 이 항목에는 시작에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.