How to access Amazon SQS from a Private EC2 Instance Using an Interface Endpoint
Table of Contents
- Introduction
- Architecture Overview
- Prerequisites
- Implementation
- Conclusion
1. Introduction
In this tutorial, we will configure an AWS VPC Interface Endpoint to allow EC2 instances in a private subnet to access Amazon SQS without requiring internet access or a NAT Gateway.
The architecture consists of two subnets: a public subnet hosting a Bastion Host and a private subnet hosting an EC2 instance. The private EC2 instance uses an IAM Role to securely access Amazon SQS through the VPC Interface Endpoint.
Using an Interface Endpoint provides private connectivity to SQS through AWS PrivateLink, eliminating the need for a NAT Gateway or public internet access for SQS traffic while improving security.
2. Architecture Overview
Download the editable here → Click here to download

- Public Subnet: Hosts the Bastion Host for SSH access.
- Private Subnet: Hosts the EC2 instance that needs S3 access.
- S3 Interface Endpoint: Provides private connectivity between the private EC2 instance and SQS.
- IAM Role: Grants the private EC2 instance permission to access SQS.
3. Prerequisites
- An active AWS account
- Basic understanding of AWS networking
- Basic Linux and SSH knowledge
4. Implementation
-
Create VPC with Public and Private Subnets
This implementation assumes you have already created a VPC with public and private subnets.
If you haven’t created your VPC and subnets yet, refer to this link: [Building a Secure AWS VPC with Public and Private Subnets].
Note: Make sure your VPC setting:
- Enable DNS resolution
- Enable DNS hostname
-
Launch the Bastion Host and Private EC2 Instance
This implementation assumes you have already launched a Bastion Host in the public subnet and a private EC2 instance in the private subnet.
If you haven’t launched these instances yet, please refer to this document: [Building a Secure AWS VPC with Public and Private Subnets].
For this lab, we will use the following EC2 instances:
Bastion host
- Subnet:
demo-public-sub-01 - Private IP:
172.16.0.11 - Public IP:
100.62.97.89 - Key pair:
ec2-user -
Security Group:
bastion-host-sg
Private EC2 Instance (ec2-01)
- Subnet:
demo-private-sub-01 - Private IP:
172.16.1.105 - Public IP: None
- Key pair:
ec2-user -
Security Group :
ec2-01-sg
- Subnet:
-
Create IAM role for EC2 instance to allow SQS Full permissions
-
Go to IAM → Roles → Create role.
-
Select AWS service as the trusted entity type and select
EC2 as the use case.
-
Attach the
AmazonSQSFullAccesspolicy.
-
Enter a role name, for example,
EC2-SQS-Access-Role.
-
Click Create role.
-
Go to IAM → Roles → Create role.
-
Associate IAM role with the Private EC2 Instance
To attach the IAM Role to an existing EC2 instance:
- Go to EC2 → Instances.
- Select your private instance (
ec2-01). -
Select Actions → Security → Modify IAM role.
- Under IAM role, select
EC2-SQS-Access-Role. -
Click Update IAM role.
-
Test SQS Access Before Creating the Interface Endpoint
Before creating the Interface Endpoint, let’s verify whether the private EC2 instance can access SQS.
-
connect to the Bastion Host using SSH.
ssh -i ec2-user.pem ec2-user@100.62.97.89
-
From the Bastion Host, SSH into the private EC2 instance:
ssh -i ec2-user ec2-user@172.16.1.105
-
Try creating SQS:
aws sqs create-queue --queue-name private-endpoint-test --region us-east-1Expected result: The command should fail or time out if the private subnet has no NAT Gateway or other working network path to SQS.
This confirms that having an IAM Role alone does not provide network connectivity to SQS.
-
connect to the Bastion Host using SSH.
-
Create VPC Interface endpoint for SQS
-
Create the Security Group for the Interface Endpoint
-
Go to VPC → Endpoints → Create endpoint.
-
Enter an endpoint name, for example,
sqs-interface-endpointand under Service category, select AWS services.
-
Search for the SQS Interface Endpoint service:
-
Select your VPC, and select Enable private DNS name.
-
Under Subnets, select the private subnet
(
demo-private-sub-01).
-
Under Security Group, select
sqs-interface-endpoint
-
Keep the default endpoint policy for this lab.
-
Click Create endpoint.
-
Create the Security Group for the Interface Endpoint
-
Test SQS Connectivity After Creating the Interface Endpoint
Reconnect to your private EC2 instance through the Bastion Host
-
Try creating an SQS
aws sqs create-queue --queue-name private-endpoint-test --region us-east-1
-
In the SQS console, you’ll see
Your private EC2 instance can now access SQS through the VPC Interface Endpoint.
-
Try creating an SQS
5. Conclusion
We have successfully configured an SQS Interface Endpoint to allow an EC2 instance in a private subnet to communicate with Amazon SQS privately using an attached IAM Role.
This architecture is useful when private EC2 instances need to send, receive, or manage SQS messages without requiring internet connectivity, improving security and reducing dependency on NAT Gateways.