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
Related
Using aws ec2 describe-images only gives the AMI IDs and other details of the EC2 instances. I need the AMI names. Is there any way to display or export the AMI names of all the EC2 Instances in an AWS account.
describe-images cli has some filtering options. We then need to query the results.
You could do something like below.
aws ec2 describe-images --filters "Name=state, Values=available" --query 'Images[*].[Name]' --ouput text
This will get all "available" image names in the corresponding region. You may use different filtering options.
Another example:
aws ec2 describe-images --filters "Name=root-device-type, Values=ebs" --query 'Images[*].[Name]' --ouput text
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"
]
I have created EC2 instance in the my office PC. It was successfully and I used it well. But when I logged to the AWS console from my home laptom - no one instance exist there and I have the error You do not have any instances in this region. I try to search instance information in other regions but do not found any.
How I can found my created instance or list all instances independently of region?
Quick way would be to use combination of AWS CLI, jq and a simple Bash for loop to iterate through each region and list the instances. Be sure to set your credentials before running
for region in `aws ec2 describe-regions | jq .Regions\[\].RegionName -r`
do
echo -e "\tRegion: ${region}"
aws ec2 describe-instances --query "Reservations[*].Instances[*].{InstanceID:InstanceId}" --output=table --region ${region}
done
You can copy post the code in your Linux shell, or run them in AWS CloudShell which gives you an authenticated shell with aws cli preinstalled
Could not connect to the endpoint URL: "https://ec2.ec2-east.amazonaws.com/" is throwing
You do not use a valid region (ec2-east)
For ec2 regions, please refer to http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region
Your command should be aws ec2 describe-instances --region xxx where xxx is in the list from http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region like aws ec2 describe-instances --region us-east-1
I am trying to find out which security groups a specific aws ec2 instance is in. I know I can do aws ec2 describe-instances
and then filter this result and do various things to it by piping the result to grep, but what has frustrated me is that I cannot use aws ec2 describe-instance-attribute --instance-id [instance-id] --attribute securityGroups or aws ec2 describe-instance-attribute --instance-id [instance-id] --attribute Groups , despite the documentation at: describe-instance-attribute suggesting that you can. Any ideas how to do this?
There is no such attribute called Groups. Refer: http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instance-attribute.html
from above link:
Same is mentioned in EC2 API Reference Guide: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstanceAttribute.html
From Above link:
Probably groupSet attribute is what you are looking for:
e,g:
aws ec2 describe-instance-attribute --instance-id [instance-id] --attribute groupSet