EC2 Instance Status using cygwin terminal - amazon-web-services

I'm trying to get into the reporting of AWS instances within my environments, and I am trying to create a script using AWS cli to generate a report of the status of EC2 instances. I'm still a beginner, so I'm learning how all this works. I was wondering if it was possible to do with a line similar to this:
AWS EC2 describe-instances --region $REGION --query 'Reservations[].Instances[?LaunchTime>=`2015-03-01`][].{id: InstanceId, type: InstanceType, launched: LaunchTime}'
I am using the Cygwin Terminal to perform this query, and any with this would be awesome thanks!
If it's possible I am also trying to see if I could get the CPU usage at that time of the report. I am still trying to understand how all this works since I am new to the AWS API.

Firstly, you will need to install the aws-sdk. Checkout the following answer for doing this in cygwin.
Then you can configure your account using aws configure and following the prompts.
After that you should be able to run aws ec2 describe-instances.

Thanks for everyone's input! I was able to figure it out here. I'm starting to understand how the population output all comes together, but right now I'm trying to put this information into at TSV file. To get the status and launch time of the instances I used the following:
aws ec2 describe-instances --region $REGION --query "Reservations[].Instances[].[InstanceId, LaunchTime, State.Name] --output text >> Instances_In_AWS.tsv
Thank you guys for your help!

Related

Why does AWS CLI rds describe-db-snapshots not include Aurora snapshots?

I can see 77 "System" snapshots in us-east-1 on the website / AWS Console. When I run the following:
aws rds describe-db-snapshots --region us-east-1 --include-shared --include-public --no-paginate --output text
... I get 35. I tried this in AWS CloudShell as well as locally with the access/secret from https://console.aws.amazon.com/iam/home?region=us-east-1#/security_credentials so this should be running with maximum (my) privileges.
I think it's excluding Aurora snapshots because the only engine value I see is postgres and not aurora-postgresql. I am going crazy trying to figure out why I can't see everything with the CLI ... any thoughts, pointers, RTFM's?
UPDATE: I added --filters "Name=engine,Values=aurora-postgresql" and sure enough the output is blank whereas --filters "Name=engine,Values=postgres" shows the 30+ entries for non-Aurora. So why are Aurora snapshots being excluded?
(Thanks to #JohnRotenstein for the answer in a comment to my question.)
There is a separate command called describe-db-cluster-snapshots that operates very similarly and outputs results for clusters, obviously, like Aurora. The only way to get the full list as seen in the Console is to combine this output with describe-db-snapshots.

How can I get the value of Usage in Service Quotas on AWS through aws ali?

I have created two instances with the package information t2.micro.
When I checked with service-quotes, there were 02 instances. How can I use AWS CLI (or API) to get value at Usage?
Hope you can help me.
You can get the total value of instances in region using something like this:
aws ec2 describe-instances --query "Reservations[].Instances[].InstanceId" --output text | wc -w
Refer this, Maybe you can get some insights

monitor all running aws instances with grafana

Im trying to identify a way to list all running instances with grafana. Have any of you been able to do this?
Essentially I want a grafana dashboard to display:
Instance-ID >> Region >> Status(up or down) >> Current running time
Do any of you know a way to achieve this?
I don't know if you can do that in grafana, but you can see just the information you want (except for the running time) in the prometheus alert module.
You can find it if you go to prometheus:9090 -> Status -> Targets
It should look something like this
Tom
For anyone that comes to this thread, I have resolved my predicament by using the aws cli.
Essentially I broke it down into two pieces, first get the list of regions, then second get all the instance information i required:
echo Grabbing instances in all regions, please wait..
for region in $(aws ec2 describe-regions --output text | cut -f3);
do
> $region.txt;
$quote="'";
aws ec2 describe-instances --region $region --query 'Reservations[].Instances[].[Tags[?Key==`Name`]| [0].Value,State.Name,InstanceType,PublicIpAddress,Placement.AvailabilityZone,LaunchTime]' --filters Name=instance-state-name,Values=running --output json >> /home/ubuntu/$region.txt; done

Aws commands are not responding

When I was trying to type "aws ec2 describe-instances" it will gives a blink cursor (AWS Command line). No results are showing.I have tried with setting the configurations for the user as well.
You have to provide instance details to get a description. like
aws ec2 describe-instances --instance-ids i-5xxxxbx

EC2 instance from AWS command line

I am very new to AWS. I've got a Windows instance running and have my aws command line configured. I've read through the AWS docs but can't seem to find exactly what I'm looking for.
How do I view my current instances from the command line?
If by view your current instances, you mean list all running instances from the command line, you can call the describe-instances command:
aws ec2 describe-instances
This will list all of your current instances.
See describe-instances
As noted in the answer by Rodrigo M, you should use describe-instances to view your EC2 instances. In general, the help command is the best way to explore the CLI. Start with aws ec2 help and try the various options. You can get more details on subcommands with aws ec2 describe-instances help as well.
The output is a bit verbose and by default in JSON. This can be a bit overwhelming and hard to read without additional processing. I'd recommend getting familiar with the --query aws CLI parameter if you intend to use the CLI interactively.
In particular, I use this for a quick overview of my EC2 instances:
aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`] | [0].Value, State.Name, PublicDnsName]' --output table
To check one particular attribute on an instance:
aws ec2 describe-instances --query Reservations[0].Instances[0].InstanceType --output text --instance-ids <my-instance-id>
The CLI is very powerful once you get comfortable with learning the commands and managing the output. It's also helpful for learning the porgramming APIs as well, since aws CLI commands generally map one-to-one with an API call.