Alias

class aws_cdk.aws_kms.Alias(scope, id, *, alias_name, target_key, removal_policy=None)

Bases: Resource

Defines a display name for a customer master key (CMK) in AWS Key Management Service (AWS KMS).

Using an alias to refer to a key can help you simplify key management. For example, when rotating keys, you can just update the alias mapping instead of tracking and changing key IDs. For more information, see Working with Aliases in the AWS Key Management Service Developer Guide.

You can also add an alias for a key by calling key.addAlias(alias).

Resource:

AWS::KMS::Alias

ExampleMetadata:

infused

Example:

# Passing an encrypted replication bucket created in a different stack.
app = App()
replication_stack = Stack(app, "ReplicationStack",
    env=Environment(
        region="us-west-1"
    )
)
key = kms.Key(replication_stack, "ReplicationKey")
alias = kms.Alias(replication_stack, "ReplicationAlias",
    # aliasName is required
    alias_name=PhysicalName.GENERATE_IF_NEEDED,
    target_key=key
)
replication_bucket = s3.Bucket(replication_stack, "ReplicationBucket",
    bucket_name=PhysicalName.GENERATE_IF_NEEDED,
    encryption_key=alias
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • alias_name (str) – The name of the alias. The name must start with alias followed by a forward slash, such as alias/. You can’t specify aliases that begin with alias/AWS. These aliases are reserved.

  • target_key (IKey) – The ID of the key for which you are creating the alias. Specify the key’s globally unique identifier or Amazon Resource Name (ARN). You can’t specify another alias.

  • removal_policy (Optional[RemovalPolicy]) – Policy to apply when the alias is removed from this stack. Default: - The alias will be deleted

Methods

add_alias(alias)

Defines a new alias for the key.

Parameters:

alias (str) –

Return type:

Alias

add_to_resource_policy(statement, allow_no_op=None)

Adds a statement to the KMS key resource policy.

Parameters:
Return type:

AddToResourcePolicyResult

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:

policy (RemovalPolicy) –

Return type:

None

grant(grantee, *actions)

Grant the indicated permissions on this key to the given principal.

Parameters:
Return type:

Grant

grant_decrypt(grantee)

Grant decryption permissions using this key to the given principal.

Parameters:

grantee (IGrantable) –

Return type:

Grant

grant_encrypt(grantee)

Grant encryption permissions using this key to the given principal.

Parameters:

grantee (IGrantable) –

Return type:

Grant

grant_encrypt_decrypt(grantee)

Grant encryption and decryption permissions using this key to the given principal.

Parameters:

grantee (IGrantable) –

Return type:

Grant

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

alias_name

The name of the alias.

alias_target_key

The Key to which the Alias refers.

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

key_arn

The ARN of the key.

key_id

1234abcd-12ab-34cd-56ef-1234567890ab).

Type:

The ID of the key (the part that looks something like

node

The construct tree node associated with this construct.

stack

The stack in which this resource is defined.

Static Methods

classmethod from_alias_attributes(scope, id, *, alias_name, alias_target_key)

Import an existing KMS Alias defined outside the CDK app.

Parameters:
  • scope (Construct) – The parent creating construct (usually this).

  • id (str) – The construct’s name.

  • alias_name (str) – Specifies the alias name. This value must begin with alias/ followed by a name (i.e. alias/ExampleAlias)

  • alias_target_key (IKey) – The customer master key (CMK) to which the Alias refers.

Return type:

IAlias

classmethod from_alias_name(scope, id, alias_name)

Import an existing KMS Alias defined outside the CDK app, by the alias name.

This method should be used instead of ‘fromAliasAttributes’ when the underlying KMS Key ARN is not available. This Alias will not have a direct reference to the KMS Key, so addAlias and grant* methods are not supported.

Parameters:
  • scope (Construct) – The parent creating construct (usually this).

  • id (str) – The construct’s name.

  • alias_name (str) – The full name of the KMS Alias (e.g., ‘alias/aws/s3’, ‘alias/myKeyAlias’).

Return type:

IAlias

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool