Look up the EC2 instance ID given an instance name.
Project description
resolve-ec2-id
Links
Introduction
This is a simple command-line tool which looks up the EC2 instance ID given an instance name:
$ resolve-ec2-id my-named-instance
i-1234567890abcdef0
Currently this tool only works with default credentials. Consider configuring them with environment variables or using a program like aws-vault.
Alternatives
This package is perhaps not so useful because very similar functionality can be accomplished with AWS CLI as follows:
aws ec2 describe-instances --filters 'Name=tag:Name,Values=my-named-instance' --query 'Reservations[*].Instances[*].{Instance:InstanceId}' --output text
The above AWS CLI command will succeed regardless of how many instances with a given tag are found.
Examples
Assuming you are using the Bash shell, to start an instance if you know the name but not the ID:
$ aws ec2 start-instances --output=yaml --instance-ids="$(resolve_ec2_id my-named-instance)"
StartingInstances:
- CurrentState:
Code: 0
Name: pending
InstanceId: i-1234567890abcdef0
PreviousState:
Code: 80
Name: stopped
This can also be used from within Python:
from resolve_ec2_id import resolve_ec2_id
ec2_id = resolve_ec2_id('my-named-instance')
Requirements
Beyond the base dependencies which install automatically, this requires either AWS CLI or boto3. (I did not make boto3
a dependency because it isn't needed if AWS CLI is already installed.)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for resolve_ec2_id-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1729a64ac30fa634f7374629876a08f2d3af98ef7e815a6fecf976335ccb5c99 |
|
MD5 | 4ddb11cbba871252bc088601d024910b |
|
BLAKE2b-256 | 58211c9c38d4dfce705595364ac6f4b0b539fe3c1dc548805de2b554103ada13 |