Skip to main content

Run commands/scripts on EC2 via AWS SSM Run Command

Project description

ssm-run-cli

Run shell commands or scripts on EC2 instances via AWS Systems Manager (SSM) Run Command.

PyPI package name: ssm-run-cli
Installed command: ssm-run-cli

Features

  • Resolve targets by:
    • EC2 instance ID (i-...)
    • Name tag / hostname / FQDN
    • Private/Public IPv4
  • Target expansion:
    • myserver{600..605}
  • Run:
    • Inline command (-- "uptime")
    • Local script file (--file ./cmd.sh)
  • SSM online filtering (with opt-out)
  • Parallel result collection for faster output fetch
  • Optional S3-backed full output (--s3-bucket) to avoid API truncation
  • Debug mode to inspect exact remote command (--debug-command)

Installation

From PyPI

pip install ssm-run-cli

Upgrade

pip install --upgrade ssm-run-cli

From source (repo)

git clone https://wwwin-github.cisco.com/skumble/ssm-cli.git
cd ssm-cli
pip install .

Requirements

  • Python 3.9+
  • AWS credentials configured (profile/role/SSO)
  • IAM permissions for:
    • ec2:DescribeInstances
    • ssm:DescribeInstanceInformation
    • ssm:SendCommand
    • ssm:ListCommandInvocations
    • ssm:GetCommandInvocation
  • If using --s3-bucket:
    • instance role needs s3:PutObject
    • caller credentials need s3:GetObject

CLI Usage

ssm-run-cli [OPTIONS] <target> [<target> ...] -- "<command>"
ssm-run-cli [OPTIONS] <target> [<target> ...] --file ./script.sh
ssm-run-cli [OPTIONS] -f hosts.txt -- "<command>"
ssm-run-cli [OPTIONS] -f hosts.txt --file ./script.sh

Options

  • -r, --region <region> AWS region (supports shortcuts: use1, euw1, aps1)
  • -f, --hosts-file <file> Read targets from file (one per line, # comments allowed)
  • --file <script.sh> Run local script file instead of inline command
  • --batch-size <1..50> Instances per SendCommand call
  • --timeout-seconds <sec> Global wait timeout
  • --poll-interval <sec> Poll interval
  • --no-online-filter Skip SSM online filtering
  • --only-failed Print output only for failed instances
  • --s3-bucket <bucket> Store/fetch full output from S3
  • --s3-prefix <prefix> Optional S3 key prefix
  • --debug-command Print decoded command and exit
  • --max-workers <n> Parallel workers for output fetching
  • -h, --help Help

Examples

1. Simple inline command

ssm-run-cli --region euw1 myserver{600..605} -- 'uptime'

2. From hosts file

ssm-run-cli -r use1 -f hosts.txt -- 'df -h'

3. Complex command using script file (recommended)

echo 'sudo grep -m1 "HUMIDITY" /mnt/logs/webex-api-streams.log' > cmd.sh
ssm-run-cli --region euw1 myserver{600..605} --file cmd.sh

4. Long-running command with higher timeout

ssm-run-cli --region euw1 --timeout-seconds 300 myserver{600..605} --file cmd.sh

5. Avoid output truncation using S3

ssm-run-cli --region euw1 --s3-bucket my-ssm-logs myserver{600..605} --file cmd.sh

6. Validate what would run (no execution)

ssm-run-cli --region euw1 --debug-command myserver601 -- 'uptime'

Notes on Quoting

For commands with JSON, nested quotes, pipes, or shell special characters, prefer --file instead of inline -- "<command>". This avoids local shell quoting issues before the command reaches the instance.

Exit Behavior

  • Returns non-zero on major failures (for example: AWS API errors, no valid targets).
  • Prints per-instance status and summary with success/failed/skipped/timeout counts.

Development

Build wheel/sdist:

python -m pip install --upgrade build
python -m build

Install local build:

python -m pip install --force-reinstall dist/*.whl

Publishing (maintainers)

python -m pip install --upgrade twine
python -m twine check dist/*
python -m twine upload dist/*

Versioning and Release Notes

  • Versioning follows Semantic Versioning (MAJOR.MINOR.PATCH).
  • Update version in pyproject.toml before each release.
  • Add release notes in CHANGELOG.md.

First Public Release Checklist

  1. Confirm package name availability on PyPI (ssm-run-cli).
  2. Verify metadata in pyproject.toml (name/version/urls/classifiers).
  3. Build artifacts:
python -m pip install --upgrade build
python -m build
python -m twine check dist/*
  1. Test local install from built wheel:
python -m pip install --force-reinstall dist/*.whl
ssm-run-cli --help
  1. Publish:
python -m twine upload dist/*
  1. Tag release in git (example):
git tag -a v0.1.0 -m "Release v0.1.0"
git push origin v0.1.0

License

Add your project license here (for example: MIT, Apache-2.0, or internal Cisco license).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssm_run_cli-0.1.2.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssm_run_cli-0.1.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file ssm_run_cli-0.1.2.tar.gz.

File metadata

  • Download URL: ssm_run_cli-0.1.2.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ssm_run_cli-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0287a05719c2a92890ebe06daf61c0d8e4fe63f5f9bd77dbee866db39fcbf29d
MD5 55511be78ece42fdd045193b529341fb
BLAKE2b-256 40d5f4dc3358a6fab13804bc107ea09a4d17a88e159633ecfb20f3d31d6f84b1

See more details on using hashes here.

File details

Details for the file ssm_run_cli-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ssm_run_cli-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ssm_run_cli-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f3dd2bb220d734ab55e682addf7f95a9c8b9a621b5d369f3371f92c6a8c11b8
MD5 df046523ffdba156a70d93238cb984e6
BLAKE2b-256 b6ca54e1d2baf360873930946b26ce24b2fcd90d8d5c99ea7e42f7d5e9ffe1a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page