Simple bash script to connect to EC2 instances via AWS Systems Manager Session Manager.
Skip looking up instance IDs in the console. Just search by name:
aws-ssm-connect web-server- AWS CLI v2
- Session Manager Plugin
- AWS credentials configured (
aws configure)
Quick install:
curl -o /usr/local/bin/aws-ssm-connect https://raw.githubusercontent.com/AleMercadal/aws-ssm-connect/main/bin/aws-ssm-connect
chmod +x /usr/local/bin/aws-ssm-connectOr with make:
git clone https://github.com/AleMercadal/aws-ssm-connect.git
cd aws-ssm-connect
make install# Basic usage
aws-ssm-connect web-server
# With AWS profile
aws-ssm-connect web-server --profile production
# With region
aws-ssm-connect web-server --region us-west-2
# Help
aws-ssm-connect --helpYour IAM user/role needs:
{
"Effect": "Allow",
"Action": ["ec2:DescribeInstances", "ssm:StartSession"],
"Resource": "*"
}Your EC2 instances need:
- IAM instance profile with
AmazonSSMManagedInstanceCorepolicy - SSM Agent running (pre-installed on most AMIs)
Can't connect?
- Instance must be in "running" state
- SSM Agent must be running
- Instance needs correct IAM role
- If you added the IAM policy after launching the instance and it still doesn't appear in Session Manager, reboot the instance so the SSM Agent can register properly
MIT