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_to_resource_policy(statement, allow_no_op=None)
Adds a statement to the KMS key resource policy.
- Parameters:
statement (
PolicyStatement
) –allow_no_op (
Optional
[bool
]) –
- Return type:
- 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:
grantee (
IGrantable
) –actions (
str
) –
- Return type:
- grant_decrypt(grantee)
Grant decryption permissions using this key to the given principal.
- Parameters:
grantee (
IGrantable
) –- Return type:
- grant_encrypt(grantee)
Grant encryption permissions using this key to the given principal.
- Parameters:
grantee (
IGrantable
) –- Return type:
- grant_encrypt_decrypt(grantee)
Grant encryption and decryption permissions using this key to the given principal.
- Parameters:
grantee (
IGrantable
) –- Return type:
- grant_generate_mac(grantee)
Grant permissions to generating MACs to the given principal.
- Parameters:
grantee (
IGrantable
) –- Return type:
- grant_verify_mac(grantee)
Grant permissions to verifying MACs to the given principal.
- Parameters:
grantee (
IGrantable
) –- Return type:
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- alias_arn
The ARN of the alias.
- Attribute:
true
- 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
(deprecated) The ARN of the alias.
- Deprecated:
use
aliasArn
instead- Stability:
deprecated
- Attribute:
true
- key_id
1234abcd-12ab-34cd-56ef-1234567890ab).
- Type:
The ID of the key (the part that looks something like
- node
The tree node.
- 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 (usuallythis
).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:
- 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.
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.
- classmethod is_owned_resource(construct)
Returns true if the construct was created by CDK, and false otherwise.
- Parameters:
construct (
IConstruct
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool