Getting ID of an instance newly launched with ec2-api-tools

前端 未结 5 1223
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 09:46

I\'m launching an EC2 instance, by invoking ec2-run-instances from simple a bash script, and want to perform further operations on that instance (e.g. associate elastic IP)

5条回答
  •  时光取名叫无心
    2020-12-14 10:04

    http://www.tothenew.com/blog/how-to-parse-json-by-command-line-in-linux/
    best tool to parse json in shell
    
    #get instance id 
    cat sample.json | jq '.Instances[0].InstanceId'|sed -e 's/^"//' -e 's/"$//' 
    #check instances is running or not 
    cat status.json | jq '.InstanceStatuses[0].InstanceState.Name'|sed -e 's/^"//' -e 's/"$//' 
    

提交回复
热议问题