Я пытаюсь получить список тегов из экземпляра EC2 и применить эти теги ко всем подключенным томам этого экземпляра, например так:
# Get the tags of the instance (filter out tags containing :aws:, since those are tags that AWS applies and they are NOT ours):
aws ec2 describe-tags --filters "Name=resource-id,Values=${instance_id}" --region us-west-2 | jq '[ .Tags[] | select( .Key | contains(":aws:") | not ) ]'
# That command produces this output:
[
{
"ResourceType": "instance",
"ResourceId": "i-0f1da295d8343635b",
"Value": "tester",
"Key": "Name"
},
{
"ResourceType": "instance",
"ResourceId": "i-0f1da295d8343635b",
"Value": "test_env",
"Key": "environment"
},
{
"ResourceType": "instance",
"ResourceId": "i-0f1da295d8343635b",
"Value": "ui_tester",
"Key": "role"
}
]
К сожалению, API create-tagsКоманда имеет вид:
aws ec2 create-tags --resources vol-076317f0fd49cb024 vol-0e91c84611369fc3f \
--tags Key=role,Value=ui_tester Key=environment,Value=test_env Key=Name,Value=tester
Как использовать jq для преобразования этого массива ключей / значений в одну строку, например:
Key=role,Value=ui_tester Key=environment,Value=test_env Key=Name,Value=tester