I am using the AWS CLI to fetching EC2 instance details. My requirements are:
1) Fetch only running EC2 instances:
- instance id
- instance tag
- instance type
- availability zone
- blockdevices name
- platform
- reserved or ondemand
However I can't able to fetch last 3 attributes (blockdevices name, platform and reserved or ondemand). When I add it in my query it is showing None. What do I need to change in query?
My query is:
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value,InstanceId,State.Name,InstanceType,Placement.AvailabilityZone]" --output table > output.txt
The output is:
| test1 | i-xxxxxxx | m1.small | running | us-east-1a |
| test2 | i-xxxxx | m1.large | running | us-east-1c |
| test3 | i-xxxxx | m1.xlarge | running | us-east-1c |
| test4 | i-xxxxxxx | m3.2xlarge | running | us-east-1a |
2) Need to fetch each instance price considering those attributes (region,type,ondemand/reserved) and put full instance details in a CSV file.