1。 ID
从适用于 Linux 的 aws-cli 版本 2.2.11 开始,我发现密钥具有 KeyPairIds ...资源 ID 。
2。关于标记键
是的,您可以使用 ec2 create-tags。使用 create-key-pair 是很成问题的。
aws ec2 create-tags help 是以下命令的参考。
一般命令和参数 ...
aws ec2 create-tags \
--resources "string" "string" --tags Key=string,Value=string ...
示例。
首先描述我的密钥以获得资源ID...密钥对ID。
aws ec2 describe-key-pairs --profile-name adrianteri-devops
输出
{
"KeyPairs": [
{
"KeyPairId": "key-044180521638ac88d",
"KeyFingerprint": "69:b4:71:46:65:40:37:59:7c:8c:5f:fa:c6:46:5a:e4:12:e0:46:54",
"KeyName": "adrianteri-devops",
"Tags": []
},
{
"KeyPairId": "key-0c010638921030fdc",
"KeyFingerprint": "21:6b:f8:05:bc:96:13:8d:ba:75:41:bb:5b:43:15:f7:9c:b0:a3:a4",
"KeyName": "ansible-devops",
"Tags": []
}
{
"KeyPairId": "key-0d047bbc242c7e0a2",
"KeyFingerprint": "69:2d:6f:6f:af:cf:45:d3:a9:d5:e7:63:b3:54:8b:85:32:67:9e:a0",
"KeyName": "test-keypair",
"Tags": []
}
]
}
(END)
现在创建标签...
aws ec2 create-tags --resources key-044180521638ac88d key-0c010638921030fdc --tags Key=Project,Value=adrianteri-com Key=CreatedBy,Value=adrianteri --profile adrianteri-devops
测试密钥对有不同的标签。
aws ec2 create-tags --resources key-0d047bbc242c7e0a2 --tags Key=Project,Value=Test Key=CreatedBy,Value=TestBot Key=Billing,Value=QualityAssuarance --profile adrianteri-live-devops
再次描述我的密钥对的结果:
{
"KeyPairs": [
{
"KeyPairId": "key-044180521638ac88d",
"KeyFingerprint": "69:b4:71:46:65:40:37:59:7c:8c:5f:fa:c6:46:5a:e4:12:e0:46:54",
"KeyName": "adrianteri-devops-keypair",
"Tags": [
{
"Key": "Project",
"Value": "adrianteri-com"
},
{
"Key": "CreatedBy",
"Value": "adrianteri"
}
]
},
{
"KeyPairId": "key-0c010638921030fdc",
"KeyFingerprint": "21:6b:f8:05:bc:96:13:8d:ba:75:41:bb:5b:43:15:f7:9c:b0:a3:a4",
"KeyName": "ansible-devops-keypair",
"Tags": [
{
"Key": "Project",
"Value": "adrianteri-com"
},
{
"Key": "CreatedBy",
"Value": "adrianteri"
}
]
},
{
"KeyPairId": "key-0d047bbc242c7e0a2",
"KeyFingerprint": "69:2d:6f:6f:af:cf:45:d3:a9:d5:e7:63:b3:54:8b:85:32:67:9e:a0",
"KeyName": "test-keypair",
"Tags": [
{
"Key": "Project",
"Value": "Test"
},
{
"Key": "CreatedBy",
"Value": "TestBot"
},
{
"Key": "Billing",
"Value": "QualityAssuarance"
}
]
}
]
}
(END)
3。按标签过滤键
也可以使用 --filters tag-key 和 tag :<key>。
tag-key
aws ec2 describe-key-pairs --filters Name=tag-key,Values=Billing --profile adrianteri-devops
输出
{
"KeyPairs": [
{
"KeyPairId": "key-0d047bbc242c7e0a2",
"KeyFingerprint": "69:2d:6f:6f:af:cf:45:d3:a9:d5:e7:63:b3:54:8b:85:32:67:9e:a0",
"KeyName": "test-keypair",
"Tags": [
{
"Key": "Project",
"Value": "Test"
},
{
"Key": "CreatedBy",
"Value": "TestBot"
},
{
"Key": "Billing",
"Value": "QualityAssurance"
}
]
}
]
}
(END)
tag :<key>
aws ec2 describe-key-pairs --filters Name=tag:CreatedBy,Values=adrianteri -profile adrianteri-devops
输出
{
"KeyPairs": [
{
"KeyPairId": "key-044180521638ac88d",
"KeyFingerprint": "69:b4:71:46:65:40:37:59:7c:8c:5f:fa:c6:46:5a:e4:12:e0:46:54",
"KeyName": "adrianteri-devops-keypair",
"Tags": [
{
"Key": "Project",
"Value": "adrianteri-com"
},
{
"Key": "CreatedBy",
"Value": "adrianteri"
}
]
},
{
"KeyPairId": "key-0c010638921030fdc",
"KeyFingerprint": "21:6b:f8:05:bc:96:13:8d:ba:75:41:bb:5b:43:15:f7:9c:b0:a3:a4",
"KeyName": "ansible-devops-keypair",
"Tags": [
{
"Key": "Project",
"Value": "adrianteri-com"
},
{
"Key": "CreatedBy",
"Value": "adrianteri"
}
]
}
]
}
(END)