DEV Community

mostafamedhat1983
mostafamedhat1983

Posted on • Edited on

Connect to EC2 using instance connect endpoint - A SIMPLE GUIDE

EC2 Instance Connect Endpoint allows you to connect to an instance without requiring the instance to have a public IPv4 address. You can connect to any instances that support TCP.
For more info and its limitations please visit this link.

To create an EC2 instance connect endpoint open VPC service from the management console, select Endpoints then Create endpoint.

create endpoint

Fill in the endpoint name, choose EC2 Instance Connect Endpoint. then select the desired VPC.
endpoint name

you can use the option "Preserve Client IP" if you want the endpoint to use your IP when establishing the connection (for example if you configured the EC2 instance's security group to only accept connections from your IP)

Preserve Client IP

select desired subnet and endpoint security group, no need to open any ports in inbound rules.
then click create endpoint. note that creation will take some time.
ceate endpoint

To create an EC2 instance, in the management console go to EC2 service. Choose Instances then launch Instances.
create an EC2 instance

fill in the EC2 instance name and choose the AMI
ec2 name and ami

choose the key pair if you want, it is optional. and select the instance type
key pair & instance type

choose the VPC and subnet (subnet I choose is private). I disabled the auto assign public IP options as I don't need it. Select the security group and make sure the appropriate port is enabled in the inbound rules (22 for linux and port 3389 for windows). If you limited the source connection to your IP, you need to use an endpoint with option "Preserve Client IP" enabled.
vpc,subnet & sg

My EC2 instance is now created, in a private subnet with no public IP and no key pair, still I can connect to it using the ec2 instance connect endpoint.

In EC2 service page select your instance and click connect
select instance

select EC2 Instance Connect, Connect using EC2 Instance Connect Endpoint, choose the end point you created then click connect.
EC2 Instance Connect

you are now connected to the EC2 instance
connected

To connect using CLI, you have to install AWS CLI first (check this link ) , create an access key (check this link ) and configure CLI using " aws configure "command.
Afer that use the following command to connect to your EC2 instance
" aws ec2-instance-connect ssh --instance-id i-1234567890example --connection-type eice "
replace i-1234567890example with your EC2 instance id
CLI connect

If you face the following error:
aws: error: argument operation: Invalid choice, valid choices are:
send-ssh-public-key | send-serial-console-ssh-public-key help
please update you AWS CLI and the problem will be solved.

Top comments (2)

Collapse
 
ahmedattia profile image
Ahmed Attia

Bravo

Collapse
 
waleedelginady profile image
Waleed Elginady

Very Informative