amazon web services - jq key, value for each shell script -


i'm trying use every key,value of output , pipe command. here i'm trying use:

instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id) aws ec2 describe-tags --filters "name=resource-id,values=$instance_id" 

with above command, have following output:

{ "tags": [     {         "resourcetype": "instance",         "resourceid": "i-0342a609edf80001a",         "value": "a-value",         "key": "a-key"     },     {         "resourcetype": "instance",         "resourceid": "i-0342a609edf80001a",         "value": "b-value",         "key": "b-key"     },     {         "resourcetype": "instance",         "resourceid": "i-0342a609edf80001a",         "value": "c-value",         "key": "c-key"     },     {         "resourcetype": "instance",         "resourceid": "i-0342a609edf80001a",         "value": "d-value",         "key": "d-key"     },     {         "resourcetype": "instance",         "resourceid": "i-0342a609edf80001a",         "value": "e-value",         "key": "e-key"     },     {         "resourcetype": "instance",         "resourceid": "i-0342a609edf80001a",         "value": "f-value",         "key": "g-key"     },     { 

now want pipe each key,value following command:

aws ec2 create-tags --resources xxxxx --tags key=h-key,value=h-value 

where quantity , values of key,value variable. believe need "for each".

may me?

it's like: each key,value, do:

aws ec2 create-tags --resources xxxxx --tags key=a-key,value=a-value aws ec2 create-tags --resources xxxxx --tags key=b-key,value=b-value aws ec2 create-tags --resources xxxxx --tags key=c-key,value=c-value aws ec2 create-tags --resources xxxxx --tags key=n...-key,value=n...-value 

has @sh directive output values quoted shell:

aws ec2 describe-tags --filters "name=resource-id,values=$instance_id" \ | jq -r '.tags[] | @sh "aws ec2 create-tags --resources xxxxx --tags key=\(.key),value=\(.value)"'  

given input, outputs

aws ec2 create-tags --resources xxxxx --tags key='a-key',value='a-value' aws ec2 create-tags --resources xxxxx --tags key='b-key',value='b-value' aws ec2 create-tags --resources xxxxx --tags key='c-key',value='c-value' aws ec2 create-tags --resources xxxxx --tags key='d-key',value='d-value' aws ec2 create-tags --resources xxxxx --tags key='e-key',value='e-value' aws ec2 create-tags --resources xxxxx --tags key='g-key',value='f-value' 

to execute commands pipe sh:

aws ec2 describe-tags ... | jq -r ... | sh  

jq quite adventure. need add "select" filter remove keys start "aws:"

jq -r '     .tags[] |      select(.key | test("^aws:") | not) |     @sh "aws ... --tags key=\(.key),value=\(.value)" ' 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -