Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resolve-ec2-id-1.0.1.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

resolve_ec2_id-1.0.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page