Access Amazon SQS from a Private EC2 Instance Using an Interface Endpoint

How to access Amazon SQS from a Private EC2 Instance Using an Interface Endpoint


Table of Contents

  1. Introduction
  2. Architecture Overview
  3. Prerequisites
  4. Implementation
  5. 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


  1. 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
  2. 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
  3. Create IAM role for EC2 instance to allow SQS Full permissions
    1. Go to IAM → Roles → Create role.
    2. Select AWS service as the trusted entity type and select EC2 as the use case.
    3. Attach the AmazonSQSFullAccess policy.
    4. Enter a role name, for example, EC2-SQS-Access-Role.
    5. Click Create role.
  4. Associate IAM role with the Private EC2 Instance

    To attach the IAM Role to an existing EC2 instance:

    1. Go to EC2 → Instances.
    2. Select your private instance (ec2-01).
    3. Select Actions → Security → Modify IAM role.
    4. Under IAM role, select EC2-SQS-Access-Role.
    5. Click Update IAM role.
  5. Test SQS Access Before Creating the Interface Endpoint

    Before creating the Interface Endpoint, let’s verify whether the private EC2 instance can access SQS.

    1. connect to the Bastion Host using SSH.
      ssh -i ec2-user.pem ec2-user@100.62.97.89
    2. From the Bastion Host, SSH into the private EC2 instance:
      ssh -i ec2-user ec2-user@172.16.1.105
    3. Try creating SQS:
      aws sqs create-queue --queue-name private-endpoint-test --region us-east-1

      Expected 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.

  6. Create VPC Interface endpoint for SQS
    1. Create the Security Group for the Interface Endpoint
    2. Go to VPC → Endpoints → Create endpoint.
    3. Enter an endpoint name, for example, sqs-interface-endpoint and under Service category, select AWS services.
    4. Search for the SQS Interface Endpoint service:
    5. Select your VPC, and select Enable private DNS name.
    6. Under Subnets, select the private subnet (demo-private-sub-01).
    7. Under Security Group, select sqs-interface-endpoint
    8. Keep the default endpoint policy for this lab.
    9. Click Create endpoint.
  7. Test SQS Connectivity After Creating the Interface Endpoint

    Reconnect to your private EC2 instance through the Bastion Host

    1. Try creating an SQS
      aws sqs create-queue --queue-name private-endpoint-test --region us-east-1
    2. In the SQS console, you’ll see

    Your private EC2 instance can now access SQS through the VPC Interface Endpoint.

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.