Este proyecto es un gestor de instancias en la nube minimalista escrito en Go. Permite crear, listar, iniciar, detener y terminar instancias en la nube de manera segura y eficiente. El objetivo de este proyecto es proporcionar una herramienta simple y fácil de usar para administrar instancias en la nube de Amazon Web Services (AWS).
- Crear instancias en la nube con una sola llamada a la API
- Listar instancias en la nube en una región específica
- Iniciar, detener y terminar instancias en la nube de manera segura
- Modo DryRun para probar el código sin afectar recursos reales
- Soporte para instancias en la nube de bajo costo (t2.micro)
- Soporte para instancias en la nube con diferentes tipos de instancias (t2.micro, t2.small, etc.)
- Go 1.17 o superior
- AWS SDK para Go
- Credenciales de AWS con permisos limitados
- Una cuenta de AWS válida
Asegúrate de tener un archivo de credenciales de AWS configurado en tu máquina. Puedes hacerlo ejecutando el siguiente comando:
aws configure
Esto te pedirá que ingreses tu AWS Access Key ID
, AWS Secret Access Key
, región predeterminada y formato de salida. Si ya tienes configurado este archivo, puedes omitir este paso.
Puedes configurar la región de AWS a través de una variable de entorno. Si no se especifica, se usará la región us-west-2
por defecto.
export AWS_REGION=tu-region
Puedes habilitar el modo DryRun para probar el código sin realizar cambios reales en los recursos de AWS.
export DRY_RUN=true
-
Clona el repositorio:
git clone https://github.com/elliotsecops/Cloud-Instance-Manager.git
-
Navega al directorio del proyecto:
cd Cloud-Instance-Manager
-
Instala las dependencias:
go get -u github.com/aws/aws-sdk-go-v2/aws
Para ejecutar el programa, simplemente ejecuta el siguiente comando:
go run main.go
El programa creará una instancia con la AMI ami-12345678
por defecto. Puedes cambiar la AMI en el código si lo deseas.
instanceID, err := crearInstancia("ami-12345678")
if err != nil {
log.Fatalf("Error al crear instancia: %v", err)
}
fmt.Printf("Instancia creada: %s\n", instanceID)
El programa listará todas las instancias en la región especificada.
instances, err := listarInstancias()
if err != nil {
log.Fatalf("Error al listar instancias: %v", err)
}
for _, instance := range instances {
fmt.Printf("ID: %s, Estado: %s\n", *instance.InstanceId, instance.State.Name)
}
El programa iniciará la instancia creada anteriormente.
if err := iniciarInstancia(instanceID); err != nil {
log.Fatalf("Error al iniciar instancia: %v", err)
}
fmt.Println("Instancia iniciada")
El programa detendrá la instancia creada anteriormente.
if err := detenerInstancia(instanceID); err != nil {
log.Fatalf("Error al detener instancia: %v", err)
}
fmt.Println("Instancia detenida")
El programa terminará la instancia creada anteriormente.
if err := terminarInstancia(instanceID); err != nil {
log.Fatalf("Error al terminar instancia: %v", err)
}
fmt.Println("Instancia terminada")
Para probar el código sin realizar cambios reales en los recursos de AWS, puedes habilitar el modo DryRun:
export DRY_RUN=true
go run main.go
Para ejecutar las pruebas unitarias, utiliza el siguiente comando:
go test -v
Para ejecutar las pruebas de integración, utiliza el siguiente comando:
go test -v -tags=integration
Este proyecto está licenciado bajo la licencia MIT. Esto significa que puedes usar, modificar y distribuir el código de manera libre, siempre y cuando se incluya la licencia original y se respeten los términos y condiciones de la misma.
Si deseas contribuir a este proyecto, por favor, sigue los siguientes pasos:
-
Clona el repositorio:
git clone https://github.com/elliotsecops/Cloud-Instance-Manager.git
-
Crea una rama nueva:
git branch my-branch
-
Realiza los cambios que desees
-
Envía un pull request con tus cambios
Si encuentras algún problema o error en el código, por favor, abre un issue en el repositorio de GitHub. Esto nos ayudará a identificar y solucionar el problema de manera más rápida.
This project is a minimalist cloud instance manager written in Go. It allows you to create, list, start, stop, and terminate cloud instances in a secure and efficient manner. The goal of this project is to provide a simple and easy-to-use tool for managing cloud instances on Amazon Web Services (AWS).
- Create cloud instances with a single API call
- List cloud instances in a specific region
- Start, stop, and terminate cloud instances securely
- DryRun mode to test the code without affecting real resources
- Support for low-cost cloud instances (t2.micro)
- Support for cloud instances with different instance types (t2.micro, t2.small, etc.)
- Go 1.17 or higher
- AWS SDK for Go
- AWS credentials with limited permissions
- A valid AWS account
Ensure you have an AWS credentials file configured on your machine. You can do this by running the following command:
aws configure
This will prompt you to enter your AWS Access Key ID
, AWS Secret Access Key
, default region, and output format. If you already have this file configured, you can skip this step.
You can configure the AWS region via an environment variable. If not specified, the default region us-west-2
will be used.
export AWS_REGION=your-region
You can enable DryRun mode to test the code without making actual changes to AWS resources.
export DRY_RUN=true
-
Clone the repository:
git clone https://github.com/elliotsecops/Cloud-Instance-Manager.git
-
Navigate to the project directory:
cd Cloud-Instance-Manager
-
Install the dependencies:
go get -u github.com/aws/aws-sdk-go-v2/aws
To run the program, simply execute the following command:
go run main.go
The program will create an instance with the default AMI ami-12345678
. You can change the AMI in the code if you wish.
instanceID, err := crearInstancia("ami-12345678")
if err != nil {
log.Fatalf("Error creating instance: %v", err)
}
fmt.Printf("Instance created: %s\n", instanceID)
The program will list all instances in the specified region.
instances, err := listarInstancias()
if err != nil {
log.Fatalf("Error listing instances: %v", err)
}
for _, instance := range instances {
fmt.Printf("ID: %s, State: %s\n", *instance.InstanceId, instance.State.Name)
}
The program will start the previously created instance.
if err := iniciarInstancia(instanceID); err != nil {
log.Fatalf("Error starting instance: %v", err)
}
fmt.Println("Instance started")
The program will stop the previously created instance.
if err := detenerInstancia(instanceID); err != nil {
log.Fatalf("Error stopping instance: %v", err)
}
fmt.Println("Instance stopped")
The program will terminate the previously created instance.
if err := terminarInstancia(instanceID); err != nil {
log.Fatalf("Error terminating instance: %v", err)
}
fmt.Println("Instance terminated")
To test the code without making actual changes to AWS resources, you can enable DryRun mode:
export DRY_RUN=true
go run main.go
To run the unit tests, use the following command:
go test -v
To run the integration tests, use the following command:
go test -v -tags=integration
This project is licensed under the MIT License. This means you can use, modify, and distribute the code freely, as long as the original license is included and its terms and conditions are respected.
If you wish to contribute to this project, please follow these steps:
-
Clone the repository:
git clone https://github.com/elliotsecops/Cloud-Instance-Manager.git
-
Create a new branch:
git branch my-branch
-
Make your changes
-
Submit a pull request with your changes
If you find any issues or bugs in the code, please open an issue on the GitHub repository. This will help us identify and fix the problem more quickly.