# 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](https://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/) 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](https://github.com/caltechads/ec2-instance-tools/releases), 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](https://github.com/pyenv/pyenv) and [pyenv-virtualenv](https://github.com/pyenv/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.
Raw data
{
"_id": null,
"home_page": "https://github.com/caltechads/ec2-instance-tools",
"name": "ec2-instance-tools",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "aws,devops",
"author": "Caltech IMSS ADS",
"author_email": "imss-ads-staff@caltech.edu",
"download_url": "https://files.pythonhosted.org/packages/4f/56/359dffc87abf20104f56a0419e2595b26e9473779d6774061d0230f66ac8/ec2-instance-tools-0.4.0.tar.gz",
"platform": null,
"description": "# ec2-instance-tools\n\nThis repository contains helper scripts for use on EC2 Amazon Linux instances.\n\n\n## sshec2 \n\n```\nUsage: sshec2 [flags] <NAME> [<command>]\n\nLook up the private IP address of a running EC2 instance by its Name tag and ssh into it.\n\nIf <command> is supplied, run that shell command on the remote instance and exit.\n\nIf multiple instances have the same Name tag, print info about all found instances\nand exit.\n\n\nOptions:\n -h, --help show this help message and exit\n -t TAG, --tag=TAG set TAG to check to find instances via this tag.\n Default: Name.\n -v, --verbose Make ssh print verbose debug messages\n```\n\n## ec2autonamer\n\n```\nUsage: ec2autonamer [flags] [<instance-id>]\n\nIf an instance was launched from an autoscaling group, it will come up with no\nName: tag. This script assigns an appropriate name tag to the instance.\n\nIf <instance-id> is not supplied, ec2autonamer will ask the EC2 instance metadata \nendpoint for the instance id.\n\nThe name will have one of the following patterns:\n\nIf this instance is an ECS container machine: ecs.{autoscalinggroup_name}.{zone-abbr}.{number},\nwhere {zone-abbr} is the availability zone name of the instance minus the region name.\n\nOtherwise: {autoscalinggroup_name}-{number}\n\nIn both cases, {number} will be chosen to be the lowest positive integer that\nis not already taken by another instance in the autoscaling group.\n\n\nOptions:\n -h, --help show this help message and exit\n```\n\nIn order to run this on an instance, the instances IAM instance profile will need to have\nthe following rights:\n\n```\n{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"ec2:CreateTags\",\n \"ec2:DeleteTags\",\n \"ec2:Describe*\"\n \"autoscaling:Describe*\"\n ],\n \"Resource\": [\"*\"]\n }\n ]\n}\n```\n\n## ec2whoami\n\n```\nUsage: whoami.py [flags]\n\nGet this instance's name tag, and save it to /etc/aws-instance-name for use by other programs.\nec2whoami will ask the EC2 instance metadata endpoint for the instance id.\n\n\nOptions:\n -h, --help show this help message and exit\n```\n\n## Installing ec2-instance-tools\n\nec2-instance-tools is a pure python package. As such, it can be installed in the\nusual python ways. For the following instructions, either install it into your\nglobal python install, or use a python [virtual environment](https://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/) to install it\nwithout polluting your global python environment.\n\n### Install via pip\n\n```\npip install ec2-instance-tools\n```\n\n### Install via `setup.py`\n\nDownload a release from [Github](https://github.com/caltechads/ec2-instance-tools/releases), then:\n\n```\nunzip ec2-instance-tools-0.4.0.zip\ncd ec2-instance-tools-0.4.0\npython setup.py install\n```\n\nOr:\n\n```\ngit clone https://github.com/caltechads/ec2-instance-tools.git\ncd ec2-instance-tools\npython setup.py install\n```\n\n### Using pyenv to install into a virtual environment (Recommended)\n\nIf you use python and frequently need to install additional python modules,\n[pyenv](https://github.com/pyenv/pyenv) and [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv)\nare extremely useful. They allow some very useful things:\n\n* Manage your virtualenvs easily on a per-project basis\n* Provide support for per-project Python versions.\n\nTo install `pyenv` and `pyenv-virtualenv` and set up your environment for the\nfirst time.\n",
"bugtrack_url": null,
"license": "",
"summary": "Useful instrumentation for EC2 instances",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/caltechads/ec2-instance-tools"
},
"split_keywords": [
"aws",
"devops"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1e65cda0a842628886307e8ea7851e4573245fbd0ad550965c45160fb7562b27",
"md5": "328964f0d1ca8bb6098e6ec7eaa0d999",
"sha256": "23574020c035214473d39b69564b4f3eb10d7e79fbf7764678794f7fb6ba9456"
},
"downloads": -1,
"filename": "ec2_instance_tools-0.4.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "328964f0d1ca8bb6098e6ec7eaa0d999",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 12660,
"upload_time": "2024-02-14T23:23:12",
"upload_time_iso_8601": "2024-02-14T23:23:12.697929Z",
"url": "https://files.pythonhosted.org/packages/1e/65/cda0a842628886307e8ea7851e4573245fbd0ad550965c45160fb7562b27/ec2_instance_tools-0.4.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4f56359dffc87abf20104f56a0419e2595b26e9473779d6774061d0230f66ac8",
"md5": "99fba1f1ed0d6bef835fbee1f2085ad1",
"sha256": "34dd5d5522915ec928d7ad5f1462123275159bf0e0b29d60b7e04ee1c3c18c99"
},
"downloads": -1,
"filename": "ec2-instance-tools-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "99fba1f1ed0d6bef835fbee1f2085ad1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11791,
"upload_time": "2024-02-14T23:23:15",
"upload_time_iso_8601": "2024-02-14T23:23:15.152430Z",
"url": "https://files.pythonhosted.org/packages/4f/56/359dffc87abf20104f56a0419e2595b26e9473779d6774061d0230f66ac8/ec2-instance-tools-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-14 23:23:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "caltechads",
"github_project": "ec2-instance-tools",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"tox": true,
"lcname": "ec2-instance-tools"
}