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
File details
Details for the file resolve-ec2-id-1.0.1.tar.gz
.
File metadata
- Download URL: resolve-ec2-id-1.0.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.5 Linux/5.13.0-1029-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6a3d04a071e07442fa8bd82382813caa6a37ae758ee3ca042bee71bfe9c5fae |
|
MD5 | 4c37f834a192f4425cd2a6f064a15433 |
|
BLAKE2b-256 | 9acc9d9c812b678687c4dcb1ed1e242340a1ba97bf29fb356e95e50e4c734682 |
File details
Details for the file resolve_ec2_id-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: resolve_ec2_id-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.5 Linux/5.13.0-1029-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bedb4dc5710c4739d81a777ebff10e8a59de0bb45862ffca72c5ff5bfab0f5f |
|
MD5 | cdbe5fa0fd8728219ee640e82ba029e2 |
|
BLAKE2b-256 | 4d3f760ae2a8486ed8de8b6fc0cf3821d72fe5d286f6d616f90743490bda271c |