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
However, this tool has slightly better error-handling; the above AWS CLI command will not generate an error in the case that no instance is found.
Installation
In order to install in a clean and isolated Python environment, it is recommended to use pipx:
pipx install resolve-ec2-id
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.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bedb4dc5710c4739d81a777ebff10e8a59de0bb45862ffca72c5ff5bfab0f5f |
|
MD5 | cdbe5fa0fd8728219ee640e82ba029e2 |
|
BLAKE2b-256 | 4d3f760ae2a8486ed8de8b6fc0cf3821d72fe5d286f6d616f90743490bda271c |