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.
-
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.
-
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.
-
Check EC2 Instance Status
- Check the current status and public IP address of the specified instance and print the information.
To build this project, you need Rust and Cargo. Follow these steps to set up and create the binary.
-
Clone the repository.
git clone <repository-url> cd ec2hoster
-
Install the required dependencies and perform a release build.
cargo build --release
-
After building, create a symbolic link in
/usr/local/bin
.sudo ln -s $(pwd)/target/release/ec2hoster /usr/local/bin/ec2hoster
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
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.
- 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 usesudo
when running commands.
This project is provided under the MIT License. See the LICENSE
file for details.