Skip to main content

Useful instrumentation for EC2 instances

Project description


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


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.

  -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


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.

  -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": [
      "Resource": ["*"]


Usage: [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.

  -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

Download a release from Github, then:

cd ec2-instance-tools-0.4.0
python install


git clone
cd ec2-instance-tools
python 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.

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

ec2-instance-tools-0.4.0.tar.gz (11.8 kB view hashes)

Uploaded source

Built Distribution

ec2_instance_tools-0.4.0-py2.py3-none-any.whl (12.7 kB view hashes)

Uploaded py2 py3

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