DEV Community

Cover image for Revolutionizing Access: No More Bastion Hosts with AWS Private Endpoint [TUTORIAL]
Saumil343
Saumil343

Posted on

Revolutionizing Access: No More Bastion Hosts with AWS Private Endpoint [TUTORIAL]

In a significant update, Amazon Web Services (AWS) has introduced a groundbreaking feature that allows seamless connections to private instances using an endpoint. This innovative solution eliminates the need for traditional bastion hosts, simplifying and enhancing the security of SSH access to private instances. In this blog post, we will explore the step-by-step process of leveraging AWS private endpoints to establish secure SSH connections to private instances, both through the AWS console and the command-line interface (CLI).

Two Ways of Connecting: There are two convenient methods to connect to private instances using AWS private endpoints: through the AWS console or AWS instance connect, and via the CLI. We will delve into both approaches, providing you with a comprehensive guide to help you utilize this exciting new feature effectively.

Process:

1.Creating an EC2 Endpoint: To begin, we need to create an EC2 endpoint, which will serve as the entry point for establishing SSH connections to private instances. Follow these steps:
a. Navigate to the AWS Management Console and access the VPC (Virtual Private Cloud) service.

b. Within the VPC dashboard, select the "Endpoints" tab and click on the "Create Endpoint" option.

c. When creating the endpoint, ensure you select the appropriate VPC, security group, and subnet.

• The security group facilitates traffic through specific ports, enabling interaction with the security group.
• The chosen subnet ensures a private connection to that subnet with a specific SSH tunnel.

Creating Endpoint-1

Creating Endpoint-2

2.Creating an EC2 Instance in a Private Subnet: Now that we have set up the EC2 endpoint, we can proceed with creating an EC2 instance in a private subnet. Follow these steps:
a. Access the EC2 service through the AWS Management Console.
b. Choose the "Instance Connect" option and select the "Connect with EC2 Endpoint" feature.
c. Select the newly created EC2 endpoint from the list to establish the connection seamlessly.

Connecting via endpoint

3.Connecting via CLI: To leverage the power of the command-line interface (CLI) for SSH connections to private instances, follow these steps:
a. Begin by configuring the AWS CLI on your local machine.
b. Open a command prompt and execute the following command to create an SSH tunnel:

aws ec2-instance-connect open-tunnel --instance-id YOUR_INSTANCE_ID --local-port 8888

c. In a new terminal window, use the SSH command to connect to the private instance by specifying the key pair file and the tunnel port:

ssh -i key.pem ec2-user@localhost -p 8888

Conclusion: With the introduction of AWS private endpoints, the process of connecting to private instances securely has been revolutionized. By following the step-by-step guide outlined in this blog post, you can eliminate the reliance on bastion hosts and establish direct SSH connections to private instances with ease. Whether through the intuitive AWS console or the power of the CLI, AWS private endpoints empower you to simplify your infrastructure while enhancing security. Embrace this exciting new feature and experience a seamless and secure SSH access solution for your private instances on AWS.

Top comments (0)