Port Forwarding Using AWS System Manager Session Manager

Posted on Oct 11, 2023

Port Forwarding Using AWS System Manager Session Manager

Session Manager is a fully managed AWS System Manager (SSM) capability that allows you to monitor infrastructure instances, edge devices, virtual machines (VMs), and on-premises servers. 

Session Manager provides a secure and auditable way to manage your infrastructure while complying with corporate policies and strict security practices across cross-platforms.

The Problem

Let’s say you are trying to use a GUI tool on your local machine (e.g., Sqlectron) to manage MySQL database instances inside the private subnet of an AWS VPC.

The scenario here is that we need to open a 3306 TCP port to allow connection to this database over the internet. However, this might not be the best way from a security perspective.

Read also: How To Use Amazon S3 For Personal Backup?

There are several ways to connect the database securely following AWS best practices, one of which has been explained below: 

The Fix

Follow the steps to connect the database more securely:

  1. Please set up a Bastion (jump host) and install all its tools. [Not recommended because that would require much extra work to set up and maintain.]
  2. Using port forwarding in AWS System Manager Session Manager can be used to connect to remote databases from a local client.

              

         Fig: Port Forwarding  to connect remote hosts in private networks
In this blog, I’ll demonstrate how to use the AWS System Manager Session Manager Capability to communicate with a remote database from the local client without the hassle of setting up a jump host.

Prerequisite

  • Session Manager can be launched using AWS CLI, so we will use AWS CLI for this process.
  • AWS CLI is already set up and configured on your local machine. Also, configure the credential chain correctly.
  • The AWS Session Manager plugin for AWS CLI must already be installed on your machine.
  • A System Manager managed EC2 instance which is either on the same network or has a connection with the remote database.
  • Check to see if your database instance can be managed remotely, meaning that no remote connections are blocked by the security group or firewall connected to it.
  • Database client sqlectron is installed on your machine.

Step 1: Setup SSM managed instance

To set up the instance, create an EC2 instance, an IAM role with the AmazonSSMManagedInstanceCore policy, assign that to the model and install the SSM agent on that server.

Know more about: AWS Well-Architected Framework Security Pillar

Then, run the following command after launching your preferred terminal application. Substitute your SSM-SSM-managed instance’s EC2 instance id for .

  • Note: Allow outbound traffic, and configure your managed instances to allow  HTTPS (port 443) to System Manager endpoints if you don’t use a VPC endpoint.
aws ssm start-session --target 

Since ,the connection was successful, we can move on to the next step.

Step 2: Open a connection forwarding session to a remote port on the MySQL server

Create an RDS instance or create your database server on a private subnet. And to initiate the port forwarding session, you will execute a System Manager Document.

Please run the following command on your terminal, replacing SSM-managed-instance-id and remote-database-host-name with their corresponding values based on your setup.

aws ssm start-session --target  --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"portNumber":["3306"],"localPortNumber":["1053"],"host":[" remote-database-host-name"]}'

Note: Since the port on local should be free, we are using local port 1053. However, as a preference, a different local port can also be chosen

Also Read: Microsoft Azure vs AWS vs Google Cloud – Comparison

Step 3: Verify connection forwarding is working (Optional)

To verify the connection forwarding is working, run the following command in a new terminal window, which will allow you to connect to the database over the CLI session:

mysql -h 127.0.0.1 --port 1053 -u admin -p

The database is connected successfully from the local using the 1053 local port.

Step 4: Connect using Sqlectron

Launch SQL Sqlectron on your local machine. Suppose you have a connection profile for this database. In that case, you may use it else create a new profile based on the connection parameters such as Username, Database type, and Server address, which are specific to your database.


       

Click save, and you will be connected to your remote database.

      

  • Please note that instead of using your database’s remote IP or hostname, you will use a localhost IP address or localhost in the Server field.

Conclusion:

Using AWS System Manager Session Manager to connect to a remote database from a local client is secure and effective for managing your infrastructure .In this blog, we have explored the steps to set up a port forwarding session to connect your database using a GUI tool like Sqlectron.


Port Forwarding Using AWS System Manager Session Manager
Saugat Tiwari

Latest Blogs

New AWS Announcement for October 2023

New AWS Announcement for October 2023


New AWS Announcement for October 2023

Adex International

Nov 08, 2023

Sustainability in the AWS Well-Architected Framework: A Comprehensive Guide

Sustainability in the AWS Well-Architected Framework: A Comprehensive Guide


Sustainability in the AWS Well-Architected Framework: A Comprehensive Guide

Adex International

Oct 19, 2023

AWS New Announcement Sept 2023

AWS New Announcement Sept 2023


AWS New Announcement Sept 2023

Adex International

Oct 17, 2023

Migrate Gitlab PostgreSQL Database to Custom Location Using Ansible

Migrate Gitlab PostgreSQL Database to Custom Location Using Ansible


Migrate Gitlab PostgreSQL Database to Custom Location Using Ansible

Saugat Tiwari

Oct 11, 2023

Mastering DevOps: Your Ultimate Guide to DevOps Managed Services

Mastering DevOps: Your Ultimate Guide to DevOps Managed Services


Mastering DevOps: Your Ultimate Guide to DevOps Managed Services

Biswash Giri

Oct 11, 2023

Discover the Benefits of Security as a Service (SECaaS) for your Business

Discover the Benefits of Security as a Service (SECaaS) for your Business


Discover the Benefits of Security as a Service (SECaaS) for your Business

Saugat Tiwari

Oct 11, 2023

Port Forwarding Using AWS System Manager Session Manager

Port Forwarding Using AWS System Manager Session Manager


Port Forwarding Using AWS System Manager Session Manager

Saugat Tiwari

Oct 11, 2023

Maximizing Directory Services with LDAP: Creating OUs, Groups, and Users for Improved Authentication and Access Control

Maximizing Directory Services with LDAP: Creating OUs, Groups, and Users for Improved Authentication and Access Control


Maximizing Directory Services with LDAP: Creating OUs, Groups, and Users for Improved Authentication and Access Control

Biswash Giri

Oct 11, 2023

AWS Migration Tools: A Comprehensive Guide

AWS Migration Tools: A Comprehensive Guide

IntroductionAWS migration tools are a comprehensive set of services and utilities provided by Amazon...


AWS Migration Tools: A Comprehensive Guide

Binaya Puri

Oct 11, 2023

Difference Between AWS Cloudwatch and Cloudtrail

Difference Between AWS Cloudwatch and Cloudtrail

AWS CloudWatch and AWS CloudTrails are sometimes difficult to distinguish. This article seeks to d...


Difference Between AWS Cloudwatch and Cloudtrail

Sabin Joshi

Oct 11, 2023

New AWS Announcements for June 2023 - Adex

New AWS Announcements for June 2023 - Adex


New AWS Announcements for June 2023 - Adex

Ravi Gupta

Oct 11, 2023

Top 7 Applications Of Cloud Computing In Various Field

Top 7 Applications Of Cloud Computing In Various Field


Top 7 Applications Of Cloud Computing In Various Field

Susmita Karki Chhetri

Oct 11, 2023

Ingesting and Monitoring Custom Metrics in CloudWatch With AWS Lambda

Ingesting and Monitoring Custom Metrics in CloudWatch With AWS Lambda


Ingesting and Monitoring Custom Metrics in CloudWatch With AWS Lambda

Tej pandey

Oct 11, 2023

7 Types of Security in Cloud Computing?

7 Types of Security in Cloud Computing?


7 Types of Security in Cloud Computing?

Mukesh Awasthi

Oct 11, 2023

Cost-effective Use cases & Benefits of Amazon S3

Cost-effective Use cases & Benefits of Amazon S3


Cost-effective Use cases & Benefits of Amazon S3

Nischal Gautam

Oct 11, 2023

IT Outsourcing: Everything You Need To Know

IT Outsourcing: Everything You Need To Know

The world has changed, and as technology advances, so does the world of work. Gone are the day...


IT Outsourcing: Everything You Need To Know

Roshan Raman Giri

Oct 11, 2023

Getting Started with Amazon Redshift in 6 Simple Steps

Getting Started with Amazon Redshift in 6 Simple Steps


Getting Started with Amazon Redshift in 6 Simple Steps

Tej pandey

Oct 11, 2023

How to Host Static Websites on AWS S3?

How to Host Static Websites on AWS S3?

How to Host Static Websites on AWS S3? Hosting a Static Website on AWS S3 has a lot of benefits....


How to Host Static Websites on AWS S3?

Ravi Gupta

Oct 11, 2023

The Importance of Managed Cloud Security for Businesses

The Importance of Managed Cloud Security for Businesses


The Importance of Managed Cloud Security for Businesses

Roshan Raman Giri

Oct 11, 2023

How To Use Amazon S3 For Personal Backup?

How To Use Amazon S3 For Personal Backup?


How To Use Amazon S3 For Personal Backup?

Tej pandey

Oct 11, 2023

Major AWS Updates &Announcements of 2023 - March

Major AWS Updates &Announcements of 2023 - March


Major AWS Updates &Announcements of 2023 - March

Roshan Raman Giri

Oct 11, 2023

How To Insert Data Into a DynamoDB Table with Boto3

How To Insert Data Into a DynamoDB Table with Boto3

DynamoDB is used for many use cases, including web and mobile applications, gaming, ad tech,...


How To Insert Data Into a DynamoDB Table with Boto3

Binaya Puri

Oct 11, 2023

How to Install and Upgrade the AWS CDK CLI

How to Install and Upgrade the AWS CDK CLI


How to Install and Upgrade the AWS CDK CLI

Nischal Gautam

Oct 11, 2023

Ultimate Guide on Creating Terraform Modules

Ultimate Guide on Creating Terraform Modules


Ultimate Guide on Creating Terraform Modules

Tej pandey

Oct 11, 2023

What is serverless computing?

What is serverless computing?


What is serverless computing?

Tej pandey

Oct 11, 2023

AWS Well-Architected Framework Security Pillar

AWS Well-Architected Framework Security Pillar

The Amazon Well-Architected Framework is a set of recommendations and practice guidelines for develo...


AWS Well-Architected Framework Security Pillar

Binaya Puri

Oct 11, 2023

Amazon FSx for Lustre, Windows, and NetApp ONTAP

Amazon FSx for Lustre, Windows, and NetApp ONTAP

Amazon FSx for Lustre, Windows, and NetApp ONTAPAmazon FSx is known for its fully managed, hig...


Amazon FSx for Lustre, Windows, and NetApp ONTAP

Ravi Gupta

Oct 11, 2023

How to Choose the Right Cloud Service Provider?

How to Choose the Right Cloud Service Provider?


How to Choose the Right Cloud Service Provider?

Tej pandey

Oct 11, 2023

25 New AWS Services Updates from AWS Re:Invent 2022

25 New AWS Services Updates from AWS Re:Invent 2022


25 New AWS Services Updates from AWS Re:Invent 2022

Susmita Karki Chhetri

Oct 11, 2023

AWS Managed Hosting Services And Dedicated Hosting Benefits

AWS Managed Hosting Services And Dedicated Hosting Benefits


AWS Managed Hosting Services And Dedicated Hosting Benefits

Tej pandey

Oct 11, 2023

What is Serverless Security? Risk & Best Practices

What is Serverless Security? Risk & Best Practices

Serverless computing  is a rising topic right now in the cloud tech industry. As per a Datad...


What is Serverless Security? Risk & Best Practices

Anup Giri

Oct 11, 2023

Difference Between Cloud Computing and Cybersecurity

Difference Between Cloud Computing and Cybersecurity


Difference Between Cloud Computing and Cybersecurity

Mukesh Awasthi

Oct 11, 2023

DevOps for Developers: How It Helps Streamline the Development Process

DevOps for Developers: How It Helps Streamline the Development Process

As per a survey done by Puppet, firms with DevOps practice have increased recovery speeds by 24 ti...


DevOps for Developers: How It Helps Streamline the Development Process

Roshan Raman Giri

Oct 11, 2023

New AWS Announcements for August 2023

New AWS Announcements for August 2023


New AWS Announcements for August 2023

Rohan Jha

Oct 11, 2023

The FinOps Chronicles

The FinOps Chronicles


The FinOps Chronicles

Anup Giri

Oct 11, 2023

AWS Auto scale Instance-Based on RabbitMQ Custom Metrics

AWS Auto scale Instance-Based on RabbitMQ Custom Metrics


AWS Auto scale Instance-Based on RabbitMQ Custom Metrics

Anup Giri

Oct 11, 2023

Overcome Merge Hell with Trunk based development and Continuous Integration

Overcome Merge Hell with Trunk based development and Continuous Integration


Overcome Merge Hell with Trunk based development and Continuous Integration

Rohan Jha

Oct 11, 2023

What's the difference between CapEX Vs OpEX in Cloud Computing?

What's the difference between CapEX Vs OpEX in Cloud Computing?


What's the difference between CapEX Vs OpEX in Cloud Computing?

Tej pandey

Oct 11, 2023

How Does Your Organization Keep Cloud Costs Under Control?

How Does Your Organization Keep Cloud Costs Under Control?


How Does Your Organization Keep Cloud Costs Under Control?

Susmita Karki Chhetri

Oct 11, 2023

Microsoft Azure vs AWS vs Google Cloud Comparison

Microsoft Azure vs AWS vs Google Cloud Comparison


Microsoft Azure vs AWS vs Google Cloud Comparison

Mukesh Awasthi

Oct 11, 2023

What are the Benefits of Amazon S3 Glacier?

What are the Benefits of Amazon S3 Glacier?


What are the Benefits of Amazon S3 Glacier?

Anup Giri

Oct 11, 2023

Leverage Azure Migrate to Discover and Assess Your AWS Instances for Smooth Migration to Azure

Leverage Azure Migrate to Discover and Assess Your AWS Instances for Smooth Migration to Azure


Leverage Azure Migrate to Discover and Assess Your AWS Instances for Smooth Migration to Azure

Rohan Jha

Oct 11, 2023