Alias L2 construct
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).
Example
// Passing an encrypted replication bucket created in a different stack.
const app = new App();
const replicationStack = new Stack(app, 'ReplicationStack', {
env: {
region: 'us-west-1',
},
});
const key = new kms.Key(replicationStack, 'ReplicationKey');
const alias = new kms.Alias(replicationStack, 'ReplicationAlias', {
// aliasName is required
aliasName: PhysicalName.GENERATE_IF_NEEDED,
targetKey: key,
});
const replicationBucket = new s3.Bucket(replicationStack, 'ReplicationBucket', {
bucketName: PhysicalName.GENERATE_IF_NEEDED,
encryptionKey: alias,
});
from aws_cdk import Environment
# 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
)
// Passing an encrypted replication bucket created in a different stack.
App app = new App();
Stack replicationStack = Stack.Builder.create(app, "ReplicationStack")
.env(Environment.builder()
.region("us-west-1")
.build())
.build();
Key key = new Key(replicationStack, "ReplicationKey");
Alias alias = Alias.Builder.create(replicationStack, "ReplicationAlias")
// aliasName is required
.aliasName(PhysicalName.GENERATE_IF_NEEDED)
.targetKey(key)
.build();
Bucket replicationBucket = Bucket.Builder.create(replicationStack, "ReplicationBucket")
.bucketName(PhysicalName.GENERATE_IF_NEEDED)
.encryptionKey(alias)
.build();
// Install: dotnet add package Amazon.CDK.Lib
// Passing an encrypted replication bucket created in a different stack.
var app = new App();
var replicationStack = new Stack(app, "ReplicationStack", new StackProps {
Env = new Environment {
Region = "us-west-1"
}
});
var key = new Key(replicationStack, "ReplicationKey");
var alias = new Alias(replicationStack, "ReplicationAlias", new AliasProps {
// aliasName is required
AliasName = PhysicalName.GENERATE_IF_NEEDED,
TargetKey = key
});
var replicationBucket = new Bucket(replicationStack, "ReplicationBucket", new BucketProps {
BucketName = PhysicalName.GENERATE_IF_NEEDED,
EncryptionKey = alias
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Passing an encrypted replication bucket created in a different stack.
app := awscdk.NewApp()
replicationStack := awscdk.Newstack(app, jsii.String("ReplicationStack"), &StackProps{
Env: &Environment{
Region: jsii.String("us-west-1"),
},
})
key := kms.NewKey(replicationStack, jsii.String("ReplicationKey"))
alias := kms.NewAlias(replicationStack, jsii.String("ReplicationAlias"), &AliasProps{
// aliasName is required
AliasName: awscdk.PhysicalName_GENERATE_IF_NEEDED(),
TargetKey: key,
})
replicationBucket := s3.NewBucket(replicationStack, jsii.String("ReplicationBucket"), &BucketProps{
BucketName: awscdk.PhysicalName_GENERATE_IF_NEEDED(),
EncryptionKey: alias,
})
Initializer
new Alias(scope: Construct, id: string, props: AliasProps)
Alias(scope: Construct, id: str, props: AliasProps)
new Alias(Construct scope, String id, AliasProps props)
new Alias(Construct scope, string id, AliasProps props)
NewAlias(Scope Construct, Id *string, Props AliasProps)
Construct Props
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.
removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= The alias will be deleted#Properties
aliasRefAliasReferencealias_refAliasReferencealiasRefAliasReferenceAliasRefAliasReferenceAliasRefAliasReferencerequired#aliasTargetKeyIKeyalias_target_keyIKeyaliasTargetKeyIKeyAliasTargetKeyIKeyAliasTargetKeyIKeyrequired#envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
keyRefKeyReferencekey_refKeyReferencekeyRefKeyReferenceKeyRefKeyReferenceKeyRefKeyReferencerequired#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#Methods
addAlias(alias: string): Alias // chainabledef add_alias(self, alias: str) -> Aliaspublic Alias addAlias(String alias)public Alias AddAlias(string alias)func AddAlias(Alias *string) Alias#addToResourcePolicy(statement: PolicyStatement, allowNoOp?: boolean): AddToResourcePolicyResultdef add_to_resource_policy(self, statement: PolicyStatement, allow_no_op: typing.Optional[bool] = None) -> AddToResourcePolicyResultpublic AddToResourcePolicyResult addToResourcePolicy(PolicyStatement statement, Boolean allowNoOp)public AddToResourcePolicyResult AddToResourcePolicy(PolicyStatement statement, bool? allowNoOp = null)func AddToResourcePolicy(Statement PolicyStatement, AllowNoOp *bool) AddToResourcePolicyResult#applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
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).
fromAliasAttributes(scope: Construct, id: string, attrs: AliasAttributes): IAlias@staticmethod def from_alias_attributes(scope: Construct, id: str, attrs: AliasAttributes) -> IAliaspublic static IAlias fromAliasAttributes(Construct scope, String id, AliasAttributes attrs)public static IAlias FromAliasAttributes(Construct scope, string id, AliasAttributes attrs)func FromAliasAttributes(Scope Construct, Id *string, Attrs AliasAttributes) IAliasstatic#3 parameters
Parameters
scopescopescopescopeScope— The parent creating construct (usuallythis).ididididId— The construct's name.attrsattrsattrsattrsAttrs— the properties of the referenced KMS Alias.
fromAliasName(scope: Construct, id: string, aliasName: string): IAlias@staticmethod def from_alias_name(scope: Construct, id: str, alias_name: str) -> IAliaspublic static IAlias fromAliasName(Construct scope, String id, String aliasName)public static IAlias FromAliasName(Construct scope, string id, string aliasName)func FromAliasName(Scope Construct, Id *string, AliasName *string) IAliasstatic#notes · 3 parameters
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 method is not supported.
If the @aws-cdk/aws-kms:applyImportedAliasPermissionsToPrincipal feature flag is set to true, the grant* methods will use the kms:ResourceAliases condition to grant permissions to the specific alias name. They will only modify the principal policy, not the key resource policy. Without the feature flag grant* methods will be a no-op.
Parameters
scopescopescopescopeScope— The parent creating construct (usuallythis).ididididId— The construct's name.aliasNamealias_namealiasNamealiasNameAliasName— The full name of the KMS Alias (e.g., 'alias/aws/s3', 'alias/myKeyAlias').
grant(grantee: IGrantable, ...actions: string[]): Grantdef grant(self, grantee: IGrantable, actions: str) -> Grantpublic Grant grant(IGrantable grantee, String actions)public Grant Grant(IGrantable grantee, string actions)func Grant(Grantee IGrantable, Actions *string) Grant#grantDecrypt(grantee: IGrantable): Grantdef grant_decrypt(self, grantee: IGrantable) -> Grantpublic Grant grantDecrypt(IGrantable grantee)public Grant GrantDecrypt(IGrantable grantee)func GrantDecrypt(Grantee IGrantable) Grant#grantEncrypt(grantee: IGrantable): Grantdef grant_encrypt(self, grantee: IGrantable) -> Grantpublic Grant grantEncrypt(IGrantable grantee)public Grant GrantEncrypt(IGrantable grantee)func GrantEncrypt(Grantee IGrantable) Grant#grantEncryptDecrypt(grantee: IGrantable): Grantdef grant_encrypt_decrypt(self, grantee: IGrantable) -> Grantpublic Grant grantEncryptDecrypt(IGrantable grantee)public Grant GrantEncryptDecrypt(IGrantable grantee)func GrantEncryptDecrypt(Grantee IGrantable) Grant#grantGenerateMac(grantee: IGrantable): Grantdef grant_generate_mac(self, grantee: IGrantable) -> Grantpublic Grant grantGenerateMac(IGrantable grantee)public Grant GrantGenerateMac(IGrantable grantee)func GrantGenerateMac(Grantee IGrantable) Grant#grantSign(grantee: IGrantable): Grantdef grant_sign(self, grantee: IGrantable) -> Grantpublic Grant grantSign(IGrantable grantee)public Grant GrantSign(IGrantable grantee)func GrantSign(Grantee IGrantable) Grant#grantSignVerify(grantee: IGrantable): Grantdef grant_sign_verify(self, grantee: IGrantable) -> Grantpublic Grant grantSignVerify(IGrantable grantee)public Grant GrantSignVerify(IGrantable grantee)func GrantSignVerify(Grantee IGrantable) Grant#grantVerify(grantee: IGrantable): Grantdef grant_verify(self, grantee: IGrantable) -> Grantpublic Grant grantVerify(IGrantable grantee)public Grant GrantVerify(IGrantable grantee)func GrantVerify(Grantee IGrantable) Grant#grantVerifyMac(grantee: IGrantable): Grantdef grant_verify_mac(self, grantee: IGrantable) -> Grantpublic Grant grantVerifyMac(IGrantable grantee)public Grant GrantVerifyMac(IGrantable grantee)func GrantVerifyMac(Grantee IGrantable) Grant#isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct 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 class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof 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 the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.