Skip to content

(kms): add Key.fromKeyId(), and make Key.fromXXX().env.region reflect the region that the key was imported from #21464

@madeline-k

Description

@madeline-k

Describe the feature

The ability to import a kms key based on the key id. And, the env for all imported keys should be the environment that they came from, not the environment of the current stack.

Use Case

When I already have the key id for a key, it is frustrating to have to go and get the ARN for that key id in order to import the key into my Construct.

const importedKey = kms.Key.fromKeyId(this, 'imported-key', 'xxx-xxx');

// should be the source region
importedKey.env.region

const anotherImportedKey = kms.Key.fromKeyId(this, 'imported-key-2', 'aws::us-east-1::.....');

// should be the source region
anotherImportedKey.env.region

Proposed Solution

I am not sure how exactly to implement fromKeyId, since you can't parse the ARN directly from the ID. But since fromKeyArn is able to get the key id without doing API lookups, I think it should be possible the other way.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

all

Environment details (OS name and version, etc.)

MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-kmsRelated to AWS Key ManagementbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions