Access of S3 bucket in Private Server Using VPC Gateway Endpoint
Tags: aws, ec2, s3, vpc
Published: 2022-02-25 04:49:08

“Challenges faced to find the solution of how to access the s3 bucket in a private server”. I have found the way by creating the vpc gateway endpoint for s3. In terms of cost and security perspective, it is free of charge and also can be secured using policy.

A VPC endpoint enables connections between a virtual private cloud (VPC) and supported services, without requiring that you use an internet gateway, NAT device, VPN connection, or AWS Direct Connect connection. Therefore, you control the specific API endpoints, sites, and services that are reachable from your VPC.

VPC endpoints are virtual devices. They are horizontally scaled, redundant, and highly available VPC components. The following are the different types of VPC endpoints. You create the type of VPC endpoint that’s required by the supported service - Interface endpoints, Gateway Load Balancer endpoints and Gateway endpoints.

In this post, you will get to know how to access the s3 bucket in a private server using vpc gateway endpoint. Here I have used two ec2 servers, a s3 bucket and IAM user with required permissions.

#Prerequisites
You’ll need an Amazon EC2 Server for this post. [Getting started with amazon EC2](https://aws.amazon.com/ec2/getting-started/) provides instructions on how to launch an EC2 Server.
You’ll need an Amazon Simple Storage Service for this post. [Getting started with Amazon Simple Storage Service](https://aws.amazon.com/s3/getting-started/) provides instructions on how to create a bucket in simple storage service. For this blog, I assume that I have created a s3 bucket and have two ec2 servers.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ksyr1a9kwvfs455n4wl3.png)
The architecture diagram shows the overall deployment architecture with data flow, vpc gateway endpoints, ec2 server and s3 bucket.

#Solution overview
The blog post consists of the following phases:
1. Create IAM User with required Permission. Check S3 bucket access from public server and private server
2. Create VPC Endpoint Gateway for S3. Check of S3 access from a private server

I have one public server and one private server. Also have a s3 bucket created as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6k3gz9otb9vew3l91r2h.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2eslqprafsyu0ijwj5a.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fls2nqh4dl7wmjzys37.png)

##Phase 1: Create IAM User with required Permission. Check S3 bucket access from public server and private server   
1. Open the IAM console, create a user named test with programmatic access. Also having full s3 access permission in user. In the bucket, created a folder and uploaded a file. Checked the s3 bucket access from the public server using aws cli. And getting the s3 bucket data from it using aws s3 ls command. Also checked with a private server for access of s3 bucket data but unable to do it and having errors.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnm8jxhdxf0anwgw198q.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trbgkzdvu7ki2b1ygx76.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iftqoyzcufravbi3jict.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25cuxc2wkyo6fqkwzj8o.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cr6m2h9ds9k5r5jy868j.png)

##Phase 2: Create VPC Endpoint Gateway for S3. Check of S3 access from a private server
1. Open the VPC console, choose the endpoints option and create an endpoint. In endpoint settings, give name as ec2-to-s3-access-endpoint and choose aws service as s3 gateway type and route table. After creation of the endpoint, check the route table configuration where you can find the endpoint route propagating automatically. Also now I am able to access the s3 bucket from a private server.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g59n6necf9mujcwfrzjj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/muee0orj2yi50hrw9m6p.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/625kdn9ceu843ew1fozm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9v8je6cbzdb75y9ylnn.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oeyx6jh405bsk9boyek1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5z271k3g29oki1ax006.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5nbvy5bhlrfoaic75dx.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8z8z6azwrel8li33qt97.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xkpas520uj73u3quqcm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9j52m90o7b6bovw59bq0.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aweqikbr7j1ru43wl4p4.png)

#Clean-up
Delete EC2 server, IAM, S3 bucket, VPC Endpoint.

#Pricing
I review the pricing and estimated cost of this example. 
Cost of VPC Gateway Endpoint = $0.0
Cost of Simple Storage Service = $1.35
Cost of EC2 = $0.0124 per On Demand Linux t2.micro Instance Hour = 1.884 Hrs = $0.02
Total Cost = $(0.0+1.35+0.02) = $1.37

#Summary
In this post, I showed “how to access the s3 bucket in a private server using vpc gateway endpoint”.
For more details on VPC Gateway Endpoint, Checkout Get started VPC Endpoints, open the [VPC console](https://ap-south-1.console.aws.amazon.com/vpc/home?region=ap-south-1#Endpoints:). To learn more, read the [VPC documentation](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-gateway.html).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)