Sitemap

Member-only story

SSM Start Session Script

5 min readAug 16, 2024

--

Press enter or click to view image in full size
Photo by Mehmet Ali Peker on Unsplash

This is a Bash script designed to automate the process of checking and installing necessary tools, managing AWS credentials, and establishing an SSH session with an AWS EC2 instance using AWS Systems Manager (SSM) for port forwarding.

Overview of the Script

This script performs several key functions:

  1. Tool Installation: It checks whether the AWS CLI and the AWS Session Manager plugin are installed. If not, it installs them.
  2. Credential Management: The script verifies if an AWS session token is available using saml2aws and prompts for login if necessary.
  3. Instance Retrieval: It retrieves the EC2 instance ID based on a provided instance name.
  4. Session Management: Finally, it opens an SSM port forwarding session to the specified instance.

Prerequisites

Before diving into the script, ensure you have the following prerequisites:

  • A Unix-based system with Bash support.
  • Sudo privileges for installing necessary tools.
  • saml2aws configured for SAML authentication.
  • An SSH configuration that allows connections over AWS SSM.

Script Breakdown

--

--

Steph Pruna
Steph Pruna

Written by Steph Pruna

Empowering Digital Landscapes with Expertise in Site Reliability Engineering and AWS