How to Connect AWS Instance and S3 Bucket with PrivateLink

AWS PrivateLink, not to be confused with peering, offers a simple solution to connect to different AWS cloud resources. It enables you to establish private connections between different AWS services and instances without exposing your data to the public internet. Network traffic that uses AWS Private Link doesn’t travel across the public internet.

In this article, we’ll dive into the step-by-step guide on how to set it up and details of when and how to use AWS PrivateLink.

Our Topology

Screenshot showing Topology for tutorial 

How to setup AWS PrivateLink step-by-step

To set up a private connection between AWS instances and S3 Bucket using PrivateLink, follow these steps:

Step 1: Create an EC2 instance 

Log in to the AWS Management Console.

Navigate to the EC2 Dashboard.

Launch an Instance. (Create this first instance on a private subnet.)

Screenshot showing Creating EC2 instance

Choose an AMI, instance type, etc based on your requirements.

Choose an existing key pair or create a new one. Download the key pair. We will need it later.

Configure instance details (e.g., VPC, Private subnet, etc).

Screenshot showing Selecting private subnet while launching ec2

Create a new security group or use an existing one. Review and Launch.

Again create another instance. (Create this second instance on the public subnet.)

Choose an existing key pair or create a new one to access your instance securely.

Configure the details (e.g, VPC, Public Subnet, etc).

Screenshot showing Selecting public subnet while launching ec2

Use the private key of the key pair to connect to the instance via SSH. (Or you can connect it through EC2 instance connect.)

Screenshot showing Using ec2 instance connect

Step 2: Create an S3 bucket

Go to the S3 services.

Click on “Create Bucket.”

Screenshot showing Creating S3 bucket

Give the bucket name and choose the region in which your ec2 instance is created.

Click on “Create bucket.”

Step 3: Create a VPC endpoint for Amazon S3

Log in to the AWS Management Console.

Navigate to the VPC Dashboard.

Click on Endpoints.

Click “Endpoints” in the VPC dashboard.

Click “Create Endpoint.”

Screenshot showing Creating endpoint

Give the name for the endpoint.

Choose “AWS Service.”

Screenshot showing Endpoint settings

Search “s3” on Services.

Select the com.amazonaws.<region>.ec2 with “Gateway” as type.

Screenshot showing Selecting endpoint service

Select the VPC in which your instance is created and also select the Route Table in which you want to attach this endpoint. (You can select the VPC and subnets you want to associate with the endpoint.)

In my case, I want to attach it to the Private Subnet – Route Table. (Because I want to access the s3 from a public ec2 instance through a private instance.)

Screenshot showing Selecting VPC and private subnet route table

Select the policy as “Full Access.”