[英]Know EC2 Instances by region
How to know EC2 instances by region from aws-cli? 如何从aws-cli知道EC2实例的区域?
Desired output: 所需的输出:
Region name name
us-west-1 instance1
us-west-1 instance2
us-west-2 instance1
us-east-1 instance1
You can only list instances via the CLI from one region at a time. 您一次只能通过CLI从一个区域列出实例。 So you would write a script that loops through each region, getting the instances in each region.
因此,您将编写一个遍历每个区域的脚本,以获取每个区域中的实例。
Here's a good starting point for a script: 这是脚本的一个很好的起点:
#!/bin/bash
all_regions="us-east-1 us-east-2 us-west-1 us-west-2"
echo "Region Name Instance ID"
for region in ${all_regions}; do
aws ec2 describe-instances --region ${region} | \
grep '"InstanceId":' | \
perl -pe "s/.*: \"(i-.*?)\".*/${region} \1/"
done
The aws command above is the AWS command line interface: 上面的aws命令是AWS命令行界面:
https://aws.amazon.com/cli/ https://aws.amazon.com/cli/
describe-instances is one of the commands for the AWS CLI: describe-instances是AWS CLI的命令之一:
http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html
grep and perl are standard utilities. grep和perl是标准实用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.