Skip to main content

ec2-instance-tools

This repository contains helper scripts for use on EC2 Amazon Linux instances.

sshec2

Usage: sshec2 [flags] <NAME> [<command>]

Look up the private IP address of a running EC2 instance by its Name tag and ssh into it.

If <command> is supplied, run that shell command on the remote instance and exit.

If multiple instances have the same Name tag, print info about all found instances
and exit.


Options:
  -h, --help         show this help message and exit
  -t TAG, --tag=TAG  set TAG to check to find instances via this tag.
                     Default: Name.
  -v, --verbose      Make ssh print verbose debug messages

ec2autonamer

Usage: ec2autonamer [flags] [<instance-id>]

If an instance was launched from an autoscaling group, it will come up with no
Name: tag.  This script assigns an appropriate name tag to the instance.

If <instance-id> is not supplied, ec2autonamer will ask the EC2 instance metadata 
endpoint for the instance id.

The name will have one of the following patterns:

If this instance is an ECS container machine: ecs.{autoscalinggroup_name}.{zone-abbr}.{number},
where {zone-abbr} is the availability zone name of the instance minus the region name.

Otherwise: {autoscalinggroup_name}-{number}

In both cases, {number} will be chosen to be the lowest positive integer that
is not already taken by another instance in the autoscaling group.


Options:
  -h, --help  show this help message and exit

In order to run this on an instance, the instances IAM instance profile will need to have the following rights:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:CreateTags",
        "ec2:DeleteTags",
        "ec2:Describe*"
        "autoscaling:Describe*"
      ],
      "Resource": ["*"]
    }
  ]
}

ec2whoami

Usage: whoami.py [flags]

Get this instance's name tag, and save it to /etc/aws-instance-name for use by other programs.
ec2whoami will ask the EC2 instance metadata endpoint for the instance id.


Options:
  -h, --help  show this help message and exit

Installing ec2-instance-tools

ec2-instance-tools is a pure python package. As such, it can be installed in the usual python ways. For the following instructions, either install it into your global python install, or use a python virtual environment to install it without polluting your global python environment.

Install via pip

pip install ec2-instance-tools

Install via setup.py

Download a release from Github, then:

unzip ec2-instance-tools-0.4.0.zip
cd ec2-instance-tools-0.4.0
python setup.py install

Or:

git clone https://github.com/caltechads/ec2-instance-tools.git
cd ec2-instance-tools
python setup.py install

Using pyenv to install into a virtual environment (Recommended)

If you use python and frequently need to install additional python modules, pyenv and pyenv-virtualenv are extremely useful. They allow some very useful things:

  • Manage your virtualenvs easily on a per-project basis
  • Provide support for per-project Python versions.

To install pyenv and pyenv-virtualenv and set up your environment for the first time.

Metadata

Release files for ec2-instance-tools 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ec2-instance-tools 0.4.0
File Size Uploaded
ec2-instance-tools-0.4.0.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ec2-instance-tools 0.4.0
File Interpreter ABI Platform
ec2_instance_tools-0.4.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 24.5 kB

Release files / ec2-instance-tools-0.4.0.tar.gz

Download URL ec2-instance-tools-0.4.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
34dd5d5522915ec928d7ad5f1462123275159bf0e0b29d60b7e04ee1c3c18c99
BLAKE2b-256 checksum
How to use checksums
4f56359dffc87abf20104f56a0419e2595b26e9473779d6774061d0230f66ac8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / ec2_instance_tools-0.4.0-py2.py3-none-any.whl

Download URL ec2_instance_tools-0.4.0-py2.py3-none-any.whl
Size 12.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
23574020c035214473d39b69564b4f3eb10d7e79fbf7764678794f7fb6ba9456
BLAKE2b-256 checksum
How to use checksums
1e65cda0a842628886307e8ea7851e4573245fbd0ad550965c45160fb7562b27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page