/ec2hoster

`Manage EC2 and Hosts` is a Rust program for starting and stopping AWS EC2 instances, as well as updating the `/etc/hosts` file and SSH configuration (`ssh_config`). This tool allows you to operate the specified EC2 instance and reflect its information on the local environment.

Primary LanguageRustMIT LicenseMIT

Manage EC2 and Hosts

Overview

Manage EC2 and Hosts is a Rust program for starting and stopping AWS EC2 instances, as well as updating the /etc/hosts file and SSH configuration (ssh_config). This tool allows you to operate the specified EC2 instance and reflect its information on the local environment.

Main Features

  1. Start EC2 Instance

    • Start an EC2 instance with the specified instance ID.
    • Retrieve the public IP address of the instance.
    • Add the instance's IP address and domain information to the /etc/hosts file.
    • Update the ssh_config file.
  2. Stop EC2 Instance

    • Stop the EC2 instance with the specified instance ID.
    • Check the instance status and print a message when the stop process is complete.
  3. Check EC2 Instance Status

    • Check the current status and public IP address of the specified instance and print the information.

Installation and Build

To build this project, you need Rust and Cargo. Follow these steps to set up and create the binary.

  1. Clone the repository.

    git clone <repository-url>
    cd ec2hoster
  2. Install the required dependencies and perform a release build.

    cargo build --release
  3. After building, create a symbolic link in /usr/local/bin.

    sudo ln -s $(pwd)/target/release/ec2hoster /usr/local/bin/ec2hoster

Usage

Use the following commands to operate the EC2 instance.

  • Start the instance

    ec2hoster start
  • Stop the instance

    ec2hoster stop
  • Check the instance status

    ec2hoster status

Configuration

This program uses the following environment settings:

  • AWS_PROFILE: Name of the AWS CLI profile to use.
  • INSTANCE_ID: The EC2 instance ID to operate.
  • TEMPLATE_PATH: Path to the template file for /etc/hosts.
  • SSH_TEMPLATE_PATH: Path to the template for the SSH configuration file.
  • SSH_CONFIG_PATH: Path to the SSH configuration file to be updated.

Notes

  • To use this tool, AWS CLI must be installed and properly configured.
  • Administrator privileges are required to modify the /etc/hosts file and SSH settings. You may need to use sudo when running commands.

License

This project is provided under the MIT License. See the LICENSE file for details.