Member-only story

Automating EC2 Instance access using Python and AWS SSM

Simon Bulmer
3 min readApr 12, 2024

Accessing Amazon EC2 instances efficiently can be a challenge, especially when you need to handle multiple instances and manage various SSH keys and permissions. I want to share a Python script I developed a while ago that simplifies the process of logging into EC2 instances via AWS Systems Manager (SSM), eliminating the need to manually search for instance IDs or manage SSH keys.

As always I utilise AWS-Runas with all my scripts.

Introduction to the Problem

Traditional methods of accessing EC2 instances often involve locating the correct instance ID, ensuring your IP is whitelisted, and managing the right SSH keys. This process becomes cumbersome and error-prone as the number of instances grows. AWS Systems Manager provides a more streamlined approach to managing and connecting to your instances securely. I’m also taking a lazy approach to EC2 instance access :)

How the Script Works

The script uses the Boto3 library, which is the Amazon Web Services (AWS) SDK for Python. It interacts with AWS services and manages resources, making it easier to automate tasks across AWS.

Step-by-step Breakdown:

--

--

Simon Bulmer
Simon Bulmer

Written by Simon Bulmer

Senior Site Reliability Engineer, Cyclist and occasional runner

No responses yet