- Newest
- Most votes
- Most comments
AWS SSM Session Manager records the raw "wire" traffic between the terminal and the instance. Because modern shells (like Zsh or Bash with autocompletion) constantly send control characters for colors, cursor movements, and line redrawing, the raw logs look like "matrix code" instead of actual commands.
1. The Quick Fix: Clean existing logs (CLI)
If you need to read the logs now, you can strip the ANSI sequences using sed or a dedicated tool like ansifilter.
Option A: This removes most color codes but might struggle with complex cursor movements (like backspaces).
sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" your_ssm_log.txt
Option B: This is much more robust for audit purposes.
# Install on Ubuntu/Debian
sudo apt-get install ansifilter
ansifilter input_log.txt > clean_audit_log.txt
see also:
- https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-logging-cloudwatch-logs.html
- https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-logging-s3.html
Option C: If you are moving to production, you cannot manually clean logs. You need an automated pipeline.
- Lambda Trigger: Set up an S3 Trigger or CloudWatch Logs Subscription Filter. When a new SSM log is saved, a Lambda function runs ansifilter (or a similar regex library) and saves a "Cleaned" version of the log to a separate "Audit-Ready" bucket/group.
- Third-Party Tools: There are open-source projects like aws-ssm-session-logger specifically designed to convert these streams into readable text or HTML.
see:
Option D: The reason your logs are so messy is often the user's shell configuration (like OhMyZsh or fancy prompts). You can force a "cleaner" environment for SSM sessions:
- Go to SSM Console > Session Manager > Preferences.
- In the Shell Profile, add a command to simplify the terminal:
export TERM=vt100
export PAGER=cat
alias ls='ls --color=never'
see:
This forces the session to use basic formatting, which generates significantly fewer ANSI codes.
Relevant content
- asked 9 months ago
- asked 5 years ago
