How yamayo/ec2ssh works
Main Components
• CLI Layer: The entry point of the application (e.g., ec2ssh.go at the root) which parses command-line options (like --profile, --region, --user) as described in the README.
• AWS EC2 Interaction: The “ec2” package (with files like ec2/service.go) encapsulates the logic for interacting with AWS, handling the retrieval of EC2 instance data using the provided AWS credentials and region settings.
• Interactive Selector (peco Integration): The “peco” component (including peco/runner.go and peco/internal/util/) integrates with peco to allow the user to interactively filter and select an EC2 instance.
• SSH Connection Handler: The “ssh” package (with config.go and run.go) contains the logic to form and execute the SSH command using the selected instance information, user details, and private key configurations.
• General Utilities: The “util” directory (and internal util in peco) provides helper functions that support common tasks across the modules.
Relationships and Interactions
• The CLI layer receives user input and environment variables (like AWS credentials and region) then directs the flow:
• It calls the AWS EC2 interaction module to fetch the list of available instances.
• The list is piped or passed to the peco integration module, which allows the user to choose the desired instance interactively.
• Once selected, the CLI ties together the chosen instance data with the SSH module, which formats the SSH command and initiates the connection.
• There are clear dependencies from the CLI to each of the specialized modules (ec2, peco, ssh), while utility functions are used by all to avoid duplication.
Architectural Patterns and Design Principles
• Modular design: The project is clearly arranged into distinct modules (AWS interaction, UI selection, SSH execution) which simplifies maintenance and testing.
• Separation of concerns: Each module is responsible for a specific task, ensuring that responsibilities such as fetching instance metadata, user interaction, and connection setup remain decoupled.
• Reusability: The presence of separate utility libraries (under util and peco/internal/util) suggests a design that encourages reusing common helper functions.
Technologies and External Dependencies
• AWS SDK (implied through use of AWS credentials and instance interaction).
• peco: An external interactive filtering tool integrated for instance selection (as referenced in both the README and the “peco” directory).
• SSH: The built-in SSH libraries/tools (managed via the ssh package) are used to handle actual connection execution.
• Environment Variables & Configuration Files: AWS credentials and configurations are processed as described in the README.