- Newest
- Most votes
- Most comments
Unfortunately, logging for Session Manager sessions that use port forwarding is limited due to the nature of the connection. Session Manager serves only as a tunnel for these connections, and the session data is encrypted, which prevents detailed logging of the session content.
However, you can still achieve some level of logging for the initiation of these sessions. While you won't be able to log the specific actions taken during the port forwarding session, you can log when a session starts and who initiated it. This can be done through AWS CloudTrail.
CloudTrail logs AWS API calls, including those made to start Session Manager sessions. When a user starts a session, including one for port forwarding, CloudTrail will record this action. The log entry will include details such as:
- The identity of the user who started the session
- The time the session was initiated
- The document name used to start the session (which could be your custom document for port forwarding)
- The target instance ID
By enabling CloudTrail and directing these logs to CloudWatch Logs, you can create a log entry that closely matches your requirement: "User X started a Session Manager Session using Document Y at time Z".
To set this up:
- Ensure CloudTrail is enabled in your AWS account.
- Configure CloudTrail to send logs to CloudWatch Logs.
- In CloudWatch Logs, you can create metrics and alerts based on these session start events if needed.
This approach will give you visibility into when port forwarding sessions are initiated and by whom, which you can then correlate with your application-level logs in the separate CloudWatch Log Group. While it doesn't provide details about the actions taken during the session, it does offer a starting point for your audit trail.
Remember to inform your users that while the content of their port forwarding sessions isn't logged, the fact that they initiated a session is recorded for security and compliance purposes.
Sources
AWS Systems Manager Session Manager - AWS Systems Manager
Step 8: (Optional) Allow and control permissions for SSH connections through Session Manager - AWS Systems Manager
Logging session data using Amazon CloudWatch Logs (console) - AWS Systems Manager
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated a year ago

I can see it in CloudTrail, and I will investigate getting it into CloudWatch from there. It would be nicer if this could be done from the SessionManager setup or Document, where we've set up the other session manager logging.