我如何在 AWS KMS 中按区域列出 KMS 密钥的授予信息和主体?

1 分钟阅读
0

我想按 AWS 区域列出我的 AWS Key Management Service (AWS KMS) 账户的 AWS KMS 密钥的授予信息和主体。

解决方法

使用 AWS 命令行界面 (AWS CLI)AWS SDK 检索 AWS KMS 密钥的授予数量和主体数量。确保您有权运行 list-keyslist-grants AWS CLI 命令。

注意:

运行以下命令列出 Windows、Linux、macOS 或 Unix 的 AWS KMS 密钥和授予信息:

aws kms list-keys --region your-region   
aws kms list-grants --region your-region --key-id your-AWS KMS-key-ID

运行以下命令查询 Linux、macOS 或 Unix 在特定区域的所有 AWS KMS 密钥:

for key in $(aws kms list-keys --region your-region --query 'Keys[].KeyId' --output text);do aws kms list-grants --region your-region --key-id $key; done

注意: 上述示例使用内置的 AWS CLI --query 选项来筛选输出的元素。

运行以下命令列出每个主体具有的 Linux、macOS 或 Unix 的 AWS KMS 密钥的授予数量:

aws kms list-grants --region your-region --key-id your-AWS KMS-key-ID | jq '.Grants[].GranteePrincipal' -r | sort | uniq -c;

注意: 您必须安装 jq 才能运行上述命令。有关安装 jq 的说明,请参阅 JSON 输出格式

AWS 官方
AWS 官方已更新 2 年前