+
Skip to content

Python CLI tools to manage AWS EC2 and ECS via SSM: Secure shell, parallel commands, port forwarding, and file transfer from the CLI.

License

Notifications You must be signed in to change notification settings

alexmllo/ssm-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSM and SSMC - AWS Systems Manager CLI Tools

A set of Python CLI tools to interact with AWS EC2 instances and ECS containers over Systems Manager (SSM). These tools help you quickly list, connect to, and manage AWS resources using AWS named profiles.

Overview

SSM and SSMC are interactive CLI tools that leverage AWS Systems Manager Session Manager to provide secure access to your AWS resources. They allow you to:

  • Connect to EC2 instances and ECS containers without opening inbound ports
  • Send commands to multiple instances in parallel
  • Set up port forwarding through SSM tunnels
  • Manage ECS containers with interactive shells
  • Transfer files securely using SCP

Prerequisites

EC2 Instances

  • [Required] AWS SSM agent installed on EC2 instances
  • [Required] IAM role with AmazonSSMManagedInstanceCore policy attached
  • [Required] For SSH/SCP features: SSM agent version 2.3.672.0 or later

ECS Containers

  • [Required] ECS tasks must have the necessary IAM permissions for SSM
  • [Required] Container must have a shell available (bash by default)

User Permissions

Required IAM permissions:

  • ec2:DescribeInstances
  • ssm:StartSession
  • ssm:TerminateSession
  • ssm:DescribeSessions
  • ssm:DescribeInstanceInformation
  • ssm:DescribeInstanceProperties
  • ssm:GetConnectionStatus
  • ecs:ListClusters
  • ecs:ListServices
  • ecs:ListTasks
  • ecs:DescribeTasks

Optional permissions:

  • ec2:DescribeRegions (for cross-region operations)

Installation

  1. Clone the repository:
git clone https://github.com/your-username/ssm-cli.git
cd ssm-cli
  1. Install the tools:
# Install both tools
make install

# Or install specific tools
make install-ssm    # Install only SSM
make install-ssmc   # Install only SSMC

Usage

SSM (EC2 Management)

ssm [COMMAND] [OPTIONS]

Available commands:

  • send-command – Run a shell command on one or more instances
  • port-forward – Start local port forwarding
  • port-forward-remote – Forward a port from the instance to another destination
  • ssh – Connect to an instance via SSH over SSM
  • scp-to – Copy files to an instance
  • (none) – If no command is given, opens an interactive SSM shell

Examples

Send a command to multiple instances:

ssm send-command -i i-0123 i-0456 -p myprofile -c 'echo "hello world"'

Port forwarding:

ssm port-forward -i i-0abcd1234efgh5678 -P 8080:3000 --profile myprofile

SSH connection:

ssm ssh -i i-0abcd1234efgh5678 -k ~/.ssh/id_rsa --profile myprofile

SSMC (ECS Container Management)

ssmc [COMMAND] [OPTIONS]

Available commands:

  • port-forward – Start port forwarding to a container
  • (none) – If no command is given, opens an interactive shell in the container

Examples

Connect to a container:

ssmc -p myprofile -c my-cluster -s my-service

Port forwarding to a container:

ssmc port-forward -p myprofile -c my-cluster -s my-service -P 9999:9000

Project Structure

ssm-cli/
├── cli.py          # Common CLI utilities
├── ssm.py          # EC2 instance management
├── ssmc.py         # ECS container management
├── utils/
│   ├── ec2.py      # EC2 client utilities
│   └── ecs.py      # ECS client utilities
├── Makefile        # Build and installation
├── requirements.txt # Python dependencies
└── README.md       # This file

License

MIT License - See LICENSE file for details

About

Python CLI tools to manage AWS EC2 and ECS via SSM: Secure shell, parallel commands, port forwarding, and file transfer from the CLI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载