Reputation: 7025
I need to export the list, that I get from AWS EC2 Console, of EC2 instances I have to a CSV/excel or similar.
It has to be in reports but cannot find it.
Upvotes: 8
Views: 42696
Reputation: 11
#!/bin/bash
regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output text)
for region in $regions; do
echo "Checking region: $region"
aws ec2 describe-instances \
--filters Name=instance-state-name,Values=stopped,running \
--query "Reservations[*].Instances[*].{Region:'$region', Name:Tags[?Key==\`Name\`]|[0].Value, Instance:InstanceId, Type:InstanceType, State:State.Name}" \
--output text \
--region $region >> instances.csv
echo "Finished checking region: $region"
done
This helps in getting all the instances in the account using AWS CLI.
Upvotes: 0
Reputation: 104196
With the AWS CLI you can use the following command (Linux):
aws ec2 describe-instances \
--filters Name=instance-state-name,Values=running \
--query 'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`]|[0].Value,Instance:InstanceId,Type:InstanceType}' \
--output text >> instances.csv
This will export the instance fields in tab-separated lines that you can later import into Excel.
Upvotes: 11
Reputation: 71
The easiest way I have found is to configure your view with all the fields you want, then, select (highlight with mouse) all the fields and copy and paste them into excel
Upvotes: 7
Reputation: 39
You can export list of all your instances as csv using Resource Groups & Tag Editor!
I can't find a way to filter by Instant State though, I'm not sure if this is possible.
Upvotes: 0
Reputation: 5665
You can use Resource Groups.
- Resource Types: AWS::EC2::instance
- Search resources
- Export search results to CSV
Update 11/2020: It is not possible to list all resources by type any longer. You have to either specify tags or Cloudformation stacks to create a resource group.
Upvotes: 7