How would you go about listing instances using aws cli in certain VPC with the Tag Name, private IP address of instance and instance id?Possible to set an internal vpc dns name with the run-instance cli command?Auto-heal an EC2 instance with an Auto Scaling Group?How to add a Tag when launching an ec2 instance using aws clisIs there a command to list AWS instances that results in short output?AWS CLI - How do I list instances and dump two specific tags along with other itemsCan't connect to a ec2 windows instance after I have enabled Enhanced Networking with ENAHow to get the Auto-assigned IP address from an Amazon Instance via aws-cliAWS SSM deleting its own files as part of its execution. Any way to safely do it?SSM Managed instance using AWS CLI and assume-roleSpawn new Aws::AutoScalingGroup instances before old are destroyed. (503 error occuring)

What information do scammers need to withdraw money from an account?

Polynomial division: Is this trick obvious?

Re-testing of regression test bug fixes or re-run regression tests?

Extract the characters before last colon

Why was my Canon Speedlite 600EX triggering other flashes?

Should I communicate in my applications that I'm unemployed out of choice rather than because nobody will have me?

is it correct to say "When it started to rain, I was in the open air."

How can a layman easily get the consensus view of what academia *thinks* about a subject?

Why are solar panels kept tilted?

The meaning of the Middle English word “king”

How to make a not so good looking person more appealing?

What is this old US Air Force plane?

Is this a group? If so, what group is it?

What information exactly does an instruction cache store?

Adding labels and comments to a matrix

Why does the headset man not get on the tractor?

Where to find every-day healthy food near Heathrow Airport?

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

Resize before convert or convert before resize?

Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?

How to describe a building set which is like LEGO without using the "LEGO" word?

Acronyms in HDD specification

Why weren't the bells paid heed to in S8E5?

How does this Martian habitat 3D printer built for NASA work?



How would you go about listing instances using aws cli in certain VPC with the Tag Name, private IP address of instance and instance id?


Possible to set an internal vpc dns name with the run-instance cli command?Auto-heal an EC2 instance with an Auto Scaling Group?How to add a Tag when launching an ec2 instance using aws clisIs there a command to list AWS instances that results in short output?AWS CLI - How do I list instances and dump two specific tags along with other itemsCan't connect to a ec2 windows instance after I have enabled Enhanced Networking with ENAHow to get the Auto-assigned IP address from an Amazon Instance via aws-cliAWS SSM deleting its own files as part of its execution. Any way to safely do it?SSM Managed instance using AWS CLI and assume-roleSpawn new Aws::AutoScalingGroup instances before old are destroyed. (503 error occuring)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








18















The closest I have get is using the following commands.



This command manage to lists all name of instances.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'


This command manage to list all private ip address, instance id and ALL tags which I don't need. I just need the name.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags'


I'm not sure why I can't execute command like this way:



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags[?Key==`Name`].Value[]'


This command works but its showing all the Tags Key names.



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags'









share|improve this question

















  • 1





    Are you just copying these commands from somewhere without trying to understand what they do?

    – Michael Hampton
    Feb 28 '14 at 15:10











  • Not really, I did try to understand how to use jq and how to get the basic json output I want. However, I couldn't find any examples for what I am trying to achieve. Using "Tags[?Key==Name].Value[]" as a filter for Key Name Value output is only possible after aws-cli v1.3.0. And I'm using a combination of --filter and jq to get the output I want. The closest command is aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags' I just need to know how to reference the Tag Key=Name using jq.

    – Imagineer
    Mar 2 '14 at 22:26


















18















The closest I have get is using the following commands.



This command manage to lists all name of instances.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'


This command manage to list all private ip address, instance id and ALL tags which I don't need. I just need the name.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags'


I'm not sure why I can't execute command like this way:



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags[?Key==`Name`].Value[]'


This command works but its showing all the Tags Key names.



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags'









share|improve this question

















  • 1





    Are you just copying these commands from somewhere without trying to understand what they do?

    – Michael Hampton
    Feb 28 '14 at 15:10











  • Not really, I did try to understand how to use jq and how to get the basic json output I want. However, I couldn't find any examples for what I am trying to achieve. Using "Tags[?Key==Name].Value[]" as a filter for Key Name Value output is only possible after aws-cli v1.3.0. And I'm using a combination of --filter and jq to get the output I want. The closest command is aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags' I just need to know how to reference the Tag Key=Name using jq.

    – Imagineer
    Mar 2 '14 at 22:26














18












18








18


9






The closest I have get is using the following commands.



This command manage to lists all name of instances.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'


This command manage to list all private ip address, instance id and ALL tags which I don't need. I just need the name.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags'


I'm not sure why I can't execute command like this way:



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags[?Key==`Name`].Value[]'


This command works but its showing all the Tags Key names.



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags'









share|improve this question














The closest I have get is using the following commands.



This command manage to lists all name of instances.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'


This command manage to list all private ip address, instance id and ALL tags which I don't need. I just need the name.



aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags'


I'm not sure why I can't execute command like this way:



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags[?Key==`Name`].Value[]'


This command works but its showing all the Tags Key names.



aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags'






aws-cli






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 28 '14 at 6:13









ImagineerImagineer

3602717




3602717







  • 1





    Are you just copying these commands from somewhere without trying to understand what they do?

    – Michael Hampton
    Feb 28 '14 at 15:10











  • Not really, I did try to understand how to use jq and how to get the basic json output I want. However, I couldn't find any examples for what I am trying to achieve. Using "Tags[?Key==Name].Value[]" as a filter for Key Name Value output is only possible after aws-cli v1.3.0. And I'm using a combination of --filter and jq to get the output I want. The closest command is aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags' I just need to know how to reference the Tag Key=Name using jq.

    – Imagineer
    Mar 2 '14 at 22:26













  • 1





    Are you just copying these commands from somewhere without trying to understand what they do?

    – Michael Hampton
    Feb 28 '14 at 15:10











  • Not really, I did try to understand how to use jq and how to get the basic json output I want. However, I couldn't find any examples for what I am trying to achieve. Using "Tags[?Key==Name].Value[]" as a filter for Key Name Value output is only possible after aws-cli v1.3.0. And I'm using a combination of --filter and jq to get the output I want. The closest command is aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags' I just need to know how to reference the Tag Key=Name using jq.

    – Imagineer
    Mar 2 '14 at 22:26








1




1





Are you just copying these commands from somewhere without trying to understand what they do?

– Michael Hampton
Feb 28 '14 at 15:10





Are you just copying these commands from somewhere without trying to understand what they do?

– Michael Hampton
Feb 28 '14 at 15:10













Not really, I did try to understand how to use jq and how to get the basic json output I want. However, I couldn't find any examples for what I am trying to achieve. Using "Tags[?Key==Name].Value[]" as a filter for Key Name Value output is only possible after aws-cli v1.3.0. And I'm using a combination of --filter and jq to get the output I want. The closest command is aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags' I just need to know how to reference the Tag Key=Name using jq.

– Imagineer
Mar 2 '14 at 22:26






Not really, I did try to understand how to use jq and how to get the basic json output I want. However, I couldn't find any examples for what I am trying to achieve. Using "Tags[?Key==Name].Value[]" as a filter for Key Name Value output is only possible after aws-cli v1.3.0. And I'm using a combination of --filter and jq to get the output I want. The closest command is aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | PrivateIpAddress, InstanceId, Tags' I just need to know how to reference the Tag Key=Name using jq.

– Imagineer
Mar 2 '14 at 22:26











6 Answers
6






active

oldest

votes


















23














You need to escape the backslashes in order to format the answer correctly.



aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'


So this is the actual command you want:



$ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'
10.101.255.10 i-91efd39b Server1
10.101.255.9 i-f1e8d4fb Server2


And you don't need .Value[]. You can just use .Value, and that will give the same output.



This is awesome, btw. I will be implementing this myself!



CORRECTION: The above won't work if the value of .Value is "None". This works better:



$ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /'
10.101.255.10 i-91efd39b Server1
10.101.255.9 i-f1e8d4fb Server2
10.101.255.8 i-f6c2450a None
10.101.255.7 i-34a6afce Server3





share|improve this answer

























  • Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

    – jorfus
    May 13 '16 at 22:26






  • 3





    If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

    – DrStrangepork
    May 17 '16 at 0:28


















7














Try this



aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text | column -t





share|improve this answer


















  • 3





    You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

    – Anthony Geoghegan
    Aug 31 '16 at 13:13











  • This works, but indeed, why does it work? | is some kind of filter?

    – aairey
    Oct 22 '18 at 18:30


















5














The above answers are OK, but my favorite of the same is;



aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --output json | tr -d 'n[] "' | perl -pe 's/i-/ni-/g' | tr ',' 't' | sed -e 's/null/None/g' | grep '^i-' | column -t


in fact, one can place it in a BASH function list list;



awsls () tr -d 'n[] "' 


then simply call from the prompt as 'awsls'






share|improve this answer























  • How do you add multiple functions in one file and just call the function you want?

    – Stryker
    Aug 14 '18 at 19:49


















2














Something like this?



aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'





share|improve this answer
































    1














    I added a filter for instance state "running". Posting it here in case that's helpful for anyone.



    My use case is slightly different, I'm generating Ansible host files so I just want private IP # name on all running hosts.



    aws ec2 describe-instances --profile=$PROFILE --filters Name=vpc-id,Values=$VPCID Name=instance-state-name,Values=running --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /' | awk 'print $1 " #" $2 '





    share|improve this answer






























      0














      Adding this for folks that will find this post when searching for how to get your instance info. You can add VPC in the select statement to receive that as well.



      In powershell you can use:



      (Get-EC2Instance -ProfileName Profile).Instances | select InstanceId,PrivateIPAddress,PublicIpAddress @Name="Servername";Expression= where key -eq "Name" | Format-Table.


      With the AWS CLI you can use:



      aws ec2 describe-instances --region=us-east-1 --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==Name].Value|[0],PrivateIpAddress,PublicIpAddress]' --output text --profile ProfileName





      share|improve this answer

























      • I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

        – JimLohse
        May 3 at 6:45











      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "2"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f578921%2fhow-would-you-go-about-listing-instances-using-aws-cli-in-certain-vpc-with-the-t%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      23














      You need to escape the backslashes in order to format the answer correctly.



      aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'


      So this is the actual command you want:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2


      And you don't need .Value[]. You can just use .Value, and that will give the same output.



      This is awesome, btw. I will be implementing this myself!



      CORRECTION: The above won't work if the value of .Value is "None". This works better:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2
      10.101.255.8 i-f6c2450a None
      10.101.255.7 i-34a6afce Server3





      share|improve this answer

























      • Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

        – jorfus
        May 13 '16 at 22:26






      • 3





        If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

        – DrStrangepork
        May 17 '16 at 0:28















      23














      You need to escape the backslashes in order to format the answer correctly.



      aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'


      So this is the actual command you want:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2


      And you don't need .Value[]. You can just use .Value, and that will give the same output.



      This is awesome, btw. I will be implementing this myself!



      CORRECTION: The above won't work if the value of .Value is "None". This works better:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2
      10.101.255.8 i-f6c2450a None
      10.101.255.7 i-34a6afce Server3





      share|improve this answer

























      • Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

        – jorfus
        May 13 '16 at 22:26






      • 3





        If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

        – DrStrangepork
        May 17 '16 at 0:28













      23












      23








      23







      You need to escape the backslashes in order to format the answer correctly.



      aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'


      So this is the actual command you want:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2


      And you don't need .Value[]. You can just use .Value, and that will give the same output.



      This is awesome, btw. I will be implementing this myself!



      CORRECTION: The above won't work if the value of .Value is "None". This works better:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2
      10.101.255.8 i-f6c2450a None
      10.101.255.7 i-34a6afce Server3





      share|improve this answer















      You need to escape the backslashes in order to format the answer correctly.



      aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'


      So this is the actual command you want:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2


      And you don't need .Value[]. You can just use .Value, and that will give the same output.



      This is awesome, btw. I will be implementing this myself!



      CORRECTION: The above won't work if the value of .Value is "None". This works better:



      $ aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-ac973bc9 --query 'Reservations[].Instances[].[PrivateIpAddress,InstanceId,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /'
      10.101.255.10 i-91efd39b Server1
      10.101.255.9 i-f1e8d4fb Server2
      10.101.255.8 i-f6c2450a None
      10.101.255.7 i-34a6afce Server3






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 29 '16 at 21:12

























      answered Feb 4 '15 at 0:06









      DrStrangeporkDrStrangepork

      453518




      453518












      • Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

        – jorfus
        May 13 '16 at 22:26






      • 3





        If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

        – DrStrangepork
        May 17 '16 at 0:28

















      • Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

        – jorfus
        May 13 '16 at 22:26






      • 3





        If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

        – DrStrangepork
        May 17 '16 at 0:28
















      Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

      – jorfus
      May 13 '16 at 22:26





      Can you please explain your sed command? I'm getting instance IDs/names off by one which might be because I'm not understanding the indirect shell expansion in the sed.

      – jorfus
      May 13 '16 at 22:26




      3




      3





      If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

      – DrStrangepork
      May 17 '16 at 0:28





      If an instance is not Named (doesn't have Tag:key=Name set), then the next instance gets printed on the same line. The first sed command prints the string "Nonen" to mitigate that problem. The second sed command strips the linefeed off the instance-id, so that the Tag:key=Name string gets printed on the same line.

      – DrStrangepork
      May 17 '16 at 0:28













      7














      Try this



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text | column -t





      share|improve this answer


















      • 3





        You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

        – Anthony Geoghegan
        Aug 31 '16 at 13:13











      • This works, but indeed, why does it work? | is some kind of filter?

        – aairey
        Oct 22 '18 at 18:30















      7














      Try this



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text | column -t





      share|improve this answer


















      • 3





        You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

        – Anthony Geoghegan
        Aug 31 '16 at 13:13











      • This works, but indeed, why does it work? | is some kind of filter?

        – aairey
        Oct 22 '18 at 18:30













      7












      7








      7







      Try this



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text | column -t





      share|improve this answer













      Try this



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text | column -t






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 31 '16 at 12:36









      alf-manalf-man

      7111




      7111







      • 3





        You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

        – Anthony Geoghegan
        Aug 31 '16 at 13:13











      • This works, but indeed, why does it work? | is some kind of filter?

        – aairey
        Oct 22 '18 at 18:30












      • 3





        You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

        – Anthony Geoghegan
        Aug 31 '16 at 13:13











      • This works, but indeed, why does it work? | is some kind of filter?

        – aairey
        Oct 22 '18 at 18:30







      3




      3





      You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

      – Anthony Geoghegan
      Aug 31 '16 at 13:13





      You should include explanation for your code. Describing how and why this code solves the problem is more useful as it helps the OP and other readers solve this and similar issues themselves.

      – Anthony Geoghegan
      Aug 31 '16 at 13:13













      This works, but indeed, why does it work? | is some kind of filter?

      – aairey
      Oct 22 '18 at 18:30





      This works, but indeed, why does it work? | is some kind of filter?

      – aairey
      Oct 22 '18 at 18:30











      5














      The above answers are OK, but my favorite of the same is;



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --output json | tr -d 'n[] "' | perl -pe 's/i-/ni-/g' | tr ',' 't' | sed -e 's/null/None/g' | grep '^i-' | column -t


      in fact, one can place it in a BASH function list list;



      awsls () tr -d 'n[] "' 


      then simply call from the prompt as 'awsls'






      share|improve this answer























      • How do you add multiple functions in one file and just call the function you want?

        – Stryker
        Aug 14 '18 at 19:49















      5














      The above answers are OK, but my favorite of the same is;



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --output json | tr -d 'n[] "' | perl -pe 's/i-/ni-/g' | tr ',' 't' | sed -e 's/null/None/g' | grep '^i-' | column -t


      in fact, one can place it in a BASH function list list;



      awsls () tr -d 'n[] "' 


      then simply call from the prompt as 'awsls'






      share|improve this answer























      • How do you add multiple functions in one file and just call the function you want?

        – Stryker
        Aug 14 '18 at 19:49













      5












      5








      5







      The above answers are OK, but my favorite of the same is;



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --output json | tr -d 'n[] "' | perl -pe 's/i-/ni-/g' | tr ',' 't' | sed -e 's/null/None/g' | grep '^i-' | column -t


      in fact, one can place it in a BASH function list list;



      awsls () tr -d 'n[] "' 


      then simply call from the prompt as 'awsls'






      share|improve this answer













      The above answers are OK, but my favorite of the same is;



      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --output json | tr -d 'n[] "' | perl -pe 's/i-/ni-/g' | tr ',' 't' | sed -e 's/null/None/g' | grep '^i-' | column -t


      in fact, one can place it in a BASH function list list;



      awsls () tr -d 'n[] "' 


      then simply call from the prompt as 'awsls'







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 7 '17 at 11:58









      Jorge de la TorreJorge de la Torre

      5111




      5111












      • How do you add multiple functions in one file and just call the function you want?

        – Stryker
        Aug 14 '18 at 19:49

















      • How do you add multiple functions in one file and just call the function you want?

        – Stryker
        Aug 14 '18 at 19:49
















      How do you add multiple functions in one file and just call the function you want?

      – Stryker
      Aug 14 '18 at 19:49





      How do you add multiple functions in one file and just call the function you want?

      – Stryker
      Aug 14 '18 at 19:49











      2














      Something like this?



      aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'





      share|improve this answer





























        2














        Something like this?



        aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'





        share|improve this answer



























          2












          2








          2







          Something like this?



          aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'





          share|improve this answer















          Something like this?



          aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed '$!N;s/n/ /'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 24 '17 at 18:25









          slm

          5,136124460




          5,136124460










          answered Aug 29 '14 at 11:51









          AlanAlan

          212




          212





















              1














              I added a filter for instance state "running". Posting it here in case that's helpful for anyone.



              My use case is slightly different, I'm generating Ansible host files so I just want private IP # name on all running hosts.



              aws ec2 describe-instances --profile=$PROFILE --filters Name=vpc-id,Values=$VPCID Name=instance-state-name,Values=running --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /' | awk 'print $1 " #" $2 '





              share|improve this answer



























                1














                I added a filter for instance state "running". Posting it here in case that's helpful for anyone.



                My use case is slightly different, I'm generating Ansible host files so I just want private IP # name on all running hosts.



                aws ec2 describe-instances --profile=$PROFILE --filters Name=vpc-id,Values=$VPCID Name=instance-state-name,Values=running --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /' | awk 'print $1 " #" $2 '





                share|improve this answer

























                  1












                  1








                  1







                  I added a filter for instance state "running". Posting it here in case that's helpful for anyone.



                  My use case is slightly different, I'm generating Ansible host files so I just want private IP # name on all running hosts.



                  aws ec2 describe-instances --profile=$PROFILE --filters Name=vpc-id,Values=$VPCID Name=instance-state-name,Values=running --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /' | awk 'print $1 " #" $2 '





                  share|improve this answer













                  I added a filter for instance state "running". Posting it here in case that's helpful for anyone.



                  My use case is slightly different, I'm generating Ansible host files so I just want private IP # name on all running hosts.



                  aws ec2 describe-instances --profile=$PROFILE --filters Name=vpc-id,Values=$VPCID Name=instance-state-name,Values=running --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text | sed 's/None$/Nonen/' | sed '$!N;s/n/ /' | awk 'print $1 " #" $2 '






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 13 '18 at 1:53









                  jorfusjorfus

                  440311




                  440311





















                      0














                      Adding this for folks that will find this post when searching for how to get your instance info. You can add VPC in the select statement to receive that as well.



                      In powershell you can use:



                      (Get-EC2Instance -ProfileName Profile).Instances | select InstanceId,PrivateIPAddress,PublicIpAddress @Name="Servername";Expression= where key -eq "Name" | Format-Table.


                      With the AWS CLI you can use:



                      aws ec2 describe-instances --region=us-east-1 --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==Name].Value|[0],PrivateIpAddress,PublicIpAddress]' --output text --profile ProfileName





                      share|improve this answer

























                      • I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

                        – JimLohse
                        May 3 at 6:45















                      0














                      Adding this for folks that will find this post when searching for how to get your instance info. You can add VPC in the select statement to receive that as well.



                      In powershell you can use:



                      (Get-EC2Instance -ProfileName Profile).Instances | select InstanceId,PrivateIPAddress,PublicIpAddress @Name="Servername";Expression= where key -eq "Name" | Format-Table.


                      With the AWS CLI you can use:



                      aws ec2 describe-instances --region=us-east-1 --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==Name].Value|[0],PrivateIpAddress,PublicIpAddress]' --output text --profile ProfileName





                      share|improve this answer

























                      • I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

                        – JimLohse
                        May 3 at 6:45













                      0












                      0








                      0







                      Adding this for folks that will find this post when searching for how to get your instance info. You can add VPC in the select statement to receive that as well.



                      In powershell you can use:



                      (Get-EC2Instance -ProfileName Profile).Instances | select InstanceId,PrivateIPAddress,PublicIpAddress @Name="Servername";Expression= where key -eq "Name" | Format-Table.


                      With the AWS CLI you can use:



                      aws ec2 describe-instances --region=us-east-1 --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==Name].Value|[0],PrivateIpAddress,PublicIpAddress]' --output text --profile ProfileName





                      share|improve this answer















                      Adding this for folks that will find this post when searching for how to get your instance info. You can add VPC in the select statement to receive that as well.



                      In powershell you can use:



                      (Get-EC2Instance -ProfileName Profile).Instances | select InstanceId,PrivateIPAddress,PublicIpAddress @Name="Servername";Expression= where key -eq "Name" | Format-Table.


                      With the AWS CLI you can use:



                      aws ec2 describe-instances --region=us-east-1 --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==Name].Value|[0],PrivateIpAddress,PublicIpAddress]' --output text --profile ProfileName






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 3 at 10:32









                      JimLohse

                      1035




                      1035










                      answered Dec 3 '18 at 22:22









                      Jose AdamsJose Adams

                      1




                      1












                      • I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

                        – JimLohse
                        May 3 at 6:45

















                      • I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

                        – JimLohse
                        May 3 at 6:45
















                      I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

                      – JimLohse
                      May 3 at 6:45





                      I edited your answer to format the commands as commands/code. Would you please double-check that the period at the end of your first command needs to be there? If not, please edit it out, thanks

                      – JimLohse
                      May 3 at 6:45

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Server Fault!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f578921%2fhow-would-you-go-about-listing-instances-using-aws-cli-in-certain-vpc-with-the-t%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

                      What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

                      Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos