AWS SDK for PHP
Developer Guide

Working with Aliases Using the AWS KMS API and the AWS SDK for PHP Version 3

An alias is an optional display name for an AWS Key Management Service (AWS KMS) customer master key (CMK).

The following examples show how to:

All the example code for the AWS SDK for PHP Version 3 is available here on GitHub.

Credentials

Before running the example code, configure your AWS credentials, as described in Credentials for the AWS SDK for PHP Version 3. Then import the AWS SDK for PHP, as described in Basic Usage Patterns of the AWS SDK for PHP Version 3.

For more information about using AWS Key Management Service (AWS KMS), see the AWS KMS Developer Guide.

Create an Alias

To create an alias for a CMK, use the CreateAlias operation. The alias must be unique in the account and AWS Region. If you create an alias for a CMK that already has an alias, CreateAlias creates another alias to the same CMK. It doesn't replace the existing alias.

Imports

require 'vendor/autoload.php'; use Aws\Kms\KmsClient; use Aws\Exception\AwsException;

Sample Code

$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $aliasName = "alias/projectKey1"; try { $result = $KmsClient->createAlias([ 'AliasName' => $aliasName, 'TargetKeyId' => $keyId, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

View an Alias

To list all aliases, use the ListAliases operation. The response includes aliases that are defined by AWS services, but are not associated with a CMK.

Imports

require 'vendor/autoload.php'; use Aws\Kms\KmsClient; use Aws\Exception\AwsException;

Sample Code

$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $limit = 10; try { $result = $KmsClient->listAliases([ 'Limit' => $limit, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Update an Alias

To associate an existing alias with a different CMK, use the UpdateAlias operation.

Imports

require 'vendor/autoload.php'; use Aws\Kms\KmsClient; use Aws\Exception\AwsException;

Sample Code

$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $aliasName = "alias/projectKey1"; try { $result = $KmsClient->updateAlias([ 'AliasName' => $aliasName, 'TargetKeyId' => $keyId, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Delete an Alias

To delete an alias, use the DeleteAlias operation. Deleting an alias has no effect on the underlying CMK.

Imports

require 'vendor/autoload.php'; use Aws\Kms\KmsClient; use Aws\Exception\AwsException;

Sample Code

$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $aliasName = "alias/projectKey1"; try { $result = $KmsClient->deleteAlias([ 'AliasName' => $aliasName, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }