How to list AWS RDS instances that are stopped - amazon-web-services

I'm trying to use the AWS CLI to list all the AWS RDS instances that I have that are in a Stopped status.
It's possible with EC2 with aws ec2 describe-instances and adding a filter --filters "Name=instance-state-name,Values=stopped".
However, with aws rds describe-db-instances, I do not find an equivalent. There is a --filter option, but only had the following options as filters: db-cluster-id, db-instance-id, dbi-resource-id, domain, engine.
So what AWS CLI command can I use to list all the RDS instances that are currently Stopped (Status=stopped)?

Use --query instead of --filters:
something like:
aws rds describe-db-instances --query '...'
https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html

You can do something like this:
aws rds describe-db-instances --query 'DBInstances[].DBInstanceStatus[]'
output:
[
"available"
]

Related

AWS CloudShell - List instances by ARN prefix

In AWS Backup, I have created a resource assignment to a backup-plan, which targets all EC2 instances.
The ARN prefix looks like this:
arn:aws:ec2:*:*:instance/*
How can I list all instances that match an ARN prefix? Either in AWS Cloudshell or with the aws cli?
I think you can try using ec2's describe-instances cli command and run it over all AWS regions :
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region
done

How can I find list of AWS EBS volumes in my account that have size >=200GIB using AWS CLI?

I am executing the command below in AWS CLI to find volumes that have size>=200GIB but the command returns nothing. But from the AWS console I can see that few volumes have a size >=200GiB
aws ec2 describe-volumes --filter "Name=size,Values= >=200GiB"
You can use the following:
aws ec2 describe-volumes --query 'Volumes[?Size > `250`].[VolumeId,Size]' --output text
I think correct format is
aws ec2 describe-volumes --query "Volumes[?Size > 100].{tag:Tags,ID:VolumeId,size:Size,type:VolumeType}"
Above command is working at my end

How to delete an EC2 instance with AWS CLI by using the EC2 tag or name?

I need to delete an Amazon EC2 instance using name or tag using the AWS CLI.
How is it possible?
To terminate an instance using the AWS Command-Line Interface (CLI):
aws ec2 terminate-instances --instance-ids i-abcd1234
See: terminate-instances — AWS CLI Command Reference
This, however, requires the **Instance ID*.
If, instead, you want to select the instance via a Tag, then you will first need to search for the instance(s).
For example, if you are searching by the instance Name (which is actually just a Tag), use:
aws ec2 describe-instances --filters Name=tag:Name,Values=Foo --query Reservations[].Instances[].InstanceId
Finally, you can combine the two queries together with:
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filters Name=tag:Name,Values=Foo --query Reservations[].Instances[].InstanceId --output text`

aws-cli only return certain fields

Given this example of aws-cli command
aws rds describe-db-cluster-snapshots
I returns a list of objects with fields.
I only want to display the fields: "SnapshotCreateTime" and "DBClusterIdentifier"
How do I do this?
AWS CLI provides built-in output filtering capabilities with the --query option.
aws rds describe-db-cluster-snapshots --query 'DBClusterSnapshots[*].[SnapshotCreateTime,DBClusterIdentifier]'
The above will work if your AWS CLI configured in the same region and have single AWS CLI profile. If AWS CLI configured in a different region and different profile then you can use below command.
aws rds describe-db-cluster-snapshots --query 'DBClusterSnapshots[*].[SnapshotCreateTime,DBClusterIdentifier]' --region us-west-2 --profile test
cli-usage-output

Finding EC2 status using EC2 API

Is there any way to find out status of AWS EC2 instances, which are running on various different regions, from one EC2 instance which is present in any one of region by using EC2 API tool ?
How this is possible ?
I got the answer :-
ec2-describe-instances instance-ID --region region
Example :-
ec2-describe-instances i-f82d5ca0 --region eu-west-1
Where instance ID is EC2 instance ID which is located in region eu-west-1
Thats all .
Or in the new unified AWS CLI, this is slightly different:
aws ec2 describe-instances --instance-id i-f82d5ca0
You can also change the --output into json, text, or a table