AWS Systems Manager Session Manager

Secure Shell Access with AWS Systems Manager Session Manager

ℹ️ What is Session Manager?
AWS Systems Manager Session Manager provides secure, auditable, browser-based interactive shell access to EC2 instances, without needing SSH keys, bastion hosts, or open inbound ports in security groups.

Benefits of Session Manager

🔒 Enhanced Security:

  • No SSH keys to manage or rotate
  • No inbound ports need to be opened
  • All sessions are logged and auditable
  • IAM-based access control

💰 Cost Optimization:

  • Removes the need for bastion hosts
  • Reduces NAT Gateway data transfer costs
  • No additional infrastructure required

⚡ Operational Excellence:

  • Centralized access management
  • Session recording capability
  • Integration with CloudTrail for compliance

Prerequisites for Session Manager

  1. IAM Role for EC2 Instances:
    • Go to the IAM console
    • Select Roles from the left navigation menu
    • Click Create role

Create VPC Create VPC Create VPC

  1. Configure the IAM role:
    • Trusted entity type: Select AWS service
    • Service: Select EC2
    • Click Next

Create VPC

  1. Attach the required policy:
    • Search for and select AmazonSSMManagedInstanceCore
    • This policy provides the minimum permissions required for Session Manager
    • Click Next

Create VPC

  1. Name and create the role:
    • Role name: Enter EC2-SessionManager-Role
    • Description: Enter IAM role for EC2 instances to use Session Manager
    • Click Create role

Create VPC Create VPC

Attach the IAM Role to the EC2 Instances

  1. Attach the role to your EC2 instances:
    • Go to the EC2 console
    • Select Instances
    • Select your EC2 Public instance
    • Click Actions > Security > Modify IAM role

Create VPC

  1. Assign the IAM role:
    • IAM role: Select EC2-SessionManager-Role
    • Click Update IAM role

Create VPC

  1. Repeat this for your EC2 Private instance:
    • Select the EC2 Private instance
    • Actions > Security > Modify IAM role
    • Select EC2-SessionManager-Role
    • Click Update IAM role

Create VPC Endpoints for Session Manager

  1. Create VPC Endpoints so the private subnet can reach Session Manager:
    • Go to the VPC console
    • Select Endpoints from the left navigation menu
    • Click Create endpoint

Create VPC

  1. Configure the SSM endpoint:
    • Name tag: Enter SSM-Endpoint
    • Service category: Select AWS services

Create VPC

  • VPC: Select your ASG VPC
  • Service name: Search for and select com.amazonaws.us-west-1.ssm Create VPC
  • Subnets: Select Private Subnet 1 and Private Subnet 2
  • Security groups: Select VPC-Endpoints-SG Create VPC

Create VPC

Create VPC

  1. Configure the additional required endpoints:
    • Create the SSM Messages endpoint: com.amazonaws.ap-southeast-1.ssmmessages
    • Use the same configuration for each endpoint:
      • VPC: Select your ASG VPC
      • Subnets: Select Private Subnet 1 and Private Subnet 2
      • Security groups: Select VPC-Endpoints-SG
      • Policy: Select Full access

Create VPC Create VPC Create VPC Create VPC Create VPC

  • Create the EC2 Messages endpoint: com.amazonaws.ap-southeast-1.ec2messages
    • Use the same configuration for each endpoint:
      • VPC: Select your ASG VPC
      • Subnets: Select Private Subnet 1 and Private Subnet 2
      • Security groups: Select VPC-Endpoints-SG
      • Policy: Select Full access

Create VPC Create VPC Create VPC Create VPC

Using Session Manager

  1. Access an instance through Session Manager:
    • Go to the Systems Manager console
    • Select Session Manager from the left navigation menu
    • Click Start session

Create VPC Create VPC

  1. Select the target instance:
    • Select your EC2 Private instance
    • Click Start session

Create VPC

Create VPC

  1. Interactive shell session:
    • You now have a secure shell session without needing SSH keys
    • Every command is logged and auditable

Update the Security Group

💡 Security Group Optimization
With Session Manager configured, you can now remove the SSH rules from your security groups:

Before (SSH required):
  Type: SSH (22)
  Source: My IP / Security Group reference

After (Session Manager):
  No inbound rule needed for shell access
  Outbound HTTPS (443) to VPC endpoints

🔒 Production Security Benefits:

  • Zero Trust Access: No network-level access required
  • Audit Trail: All sessions are logged to CloudTrail
  • Fine-Grained Permissions: IAM policies control access
  • Session Recording: Optional session recording for compliance

💰 Cost Benefits:

  • No Bastion Hosts: Eliminates EC2 costs for jump boxes
  • Reduced Data Transfer: Direct access reduces NAT Gateway usage
  • No SSH Key Management: Reduces operational overhead

⚡ Operational Benefits:

  • Browser-Based: No SSH client software required
  • Cross-Platform: Works on any device with a web browser
  • Centralized Management: A single console for all access
  • Integration-Ready: Works with your existing IAM policies and roles