Skip to main content
aws-ec2-tool     
A small toolbox for working with EC2. Including:

hop: a CLI for SSHing to EC2 using SSM-backed keys



Overview

(Placeholder)

See setup.cfg to find the latest info about required versions of boto.

See the Usage section for more details


Installation

See pypi for available releases.

pip install aws-ec2-tool

Usage

After installation, you can invoke this tool as either hop or python -m hop.

Usage info follows:

$ hop --help

Usage: hop [OPTIONS] IDENTIFIER [COMMAND]...

  Tool for SSH'ing in to EC2 with SSM-backed keys.

  Example usage:

      hop <instance_id>     hop <reservation_id>     hop <instance_name>
      hop <ip_address>

Options:
  -s, --ssm-prefix TEXT  default SSM prefix to use for key-search
  -l, --list-only        list instances
  --profile TEXT         AWS profile to use
  -s, --script TEXT      Script to run
  --user TEXT            username (default will attempt auto-detect)
  --help                 Show this message and exit.

Using hop with IaC

It's most convenient and powerful if you're using hop under circumstances that guarantee that your SSH keys are already stored in SSM according to strong conventions. In other words.. it's a good idea to manage this stuff with infrastructure-as-code.

Here's some quick information and examples about how to get started doing that with terraform. Here's some of the resources involved:

Let's get keys stored in SSM first. The commands below use the ssm command via the aws-ssm-tool. (This tool is an explicit dependency of this project; it's already installed if you ran pip for this project.)

# generate a new keypair
$ ssh-keygen -b 2048 -t rsa -f test.key -q -N ""
$ ls test.key*
test.key  test.key.pub

# put keypairs into SSM at a predictable location.
$ ssm put /your_org/keypairs/test/pub --file test.key.pub
$ ssm put /your_org/keypairs/test/pem --file test.key

# optional: get the value you set, if you want to test
$ ssm get /your_org/keypairs/test/pub

The keypair is in SSM now, but there's no actual keypair that we can use with EC2 yet. Create the keypair from what's stored in SSM with terraform like this:

data "aws_ssm_parameter" "pub_key" {
  name = "/org_name/keypairs/key_name/pub"
}

resource "aws_key_pair" "appservers" {
  key_name   = "appservers-key"
  public_key = data.aws_ssm_parameter.pub_key.value
}

Now you can use this keypair with EC2.

data "aws_ami" "ubuntu" {
  most_recent = true
  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
  }
  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }
  owners = ["099720109477"] # Canonical
}

resource "aws_instance" "appserver-test" {
  ami           = data.aws_ami.ubuntu
  instance_type = "t3.micro"
  key_name = aws_key_pair.appservers.key_name
  tags = {
    Name = "my-appserver-name"
  }
  subnet_id = ".."
  vpc_security_group_ids=[".."]
}

Metadata

Release files for aws-ec2-tool 2024.3.13.1.54

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

Source distribution (sdist)

Source distribution for aws-ec2-tool 2024.3.13.1.54
File Size Uploaded Provenance Actions
aws-ec2-tool-2024.3.13.1.54.tar.gz 10.3 kB Without provenance Details for aws-ec2-tool-2024.3.13.1.54.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-ec2-tool 2024.3.13.1.54
File Interpreter ABI Platform Actions
aws_ec2_tool-2024.3.13.1.54-py3-none-any.whl Python 3 none any Details for aws_ec2_tool-2024.3.13.1.54-py3-none-any.whl

Total release size: 22.1 kB

Release files / aws-ec2-tool-2024.3.13.1.54.tar.gz

Download URL aws-ec2-tool-2024.3.13.1.54.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c5cccf777ca4149f3ee4bed3efb0ef904925f24282f3bc71320ac10cd11d5c7e
BLAKE2b-256 checksum
How to use checksums
e4d1586fb51d7b4d4ef865acfb5e24b48f453a3d915cc15edcd6ad9545f7a691
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / aws_ec2_tool-2024.3.13.1.54-py3-none-any.whl

Download URL aws_ec2_tool-2024.3.13.1.54-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
782fe8e00e6297b17ec4f8777235804a23ba6023ecb54886ae71ad96f92462c3
BLAKE2b-256 checksum
How to use checksums
7c109b44dd61f0ddcd99c585d2c033793c08f0acdd69a4448bb92d94555f5972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for aws-ec2-tool 2024.3.13.1.54

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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