- 最新
- 投票最多
- 评论最多
Hello.
I think it's probably not possible to do this from the management console, so I think it's better to use the AWS CLI.
Therefore, I think it is better to use a shell script like the one below.
This is the script I used in the past when I wanted to check the number of instances in my AWS account.
#!/bin/bash
output="ec2_instances.csv"
echo "Region,InstanceId" > $output
regions=$(aws ec2 describe-regions --output text --query 'Regions[].RegionName')
for region in $regions; do
instances=$(aws ec2 describe-instances --region $region)
for instance_id in $(echo "$instances" | jq -r -c '.Reservations[].Instances[].InstanceId'); do
echo "$region,$instance_id" >> $output
done
done
By the way, how many EC2 machines are there in one region?
If there are a large number of EC2 machines, the response to "describe-instances" will include a field called "NextToken", so you will need to add a process that repeats until there is no field left.
Above should work without a need to worry about pagination (NextToken).
... by default the AWS CLI automatically makes multiple calls to return all possible results to create pagination.
[from https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-pagination.html ]
相关内容
- AWS 官方已更新 1 年前