Skip to content

How to get s3 files from public ec2 without data transfer costs

0

Hello everyone, Well basically i have a ec2 in a public subnet and there is a script running ínside this instance that get large files from s3 via cloudfront dns and i need to prevent this data transfer cost, i read about vpc gateway endpoint But look like that ec2 need to be in an private subnet, but i dont know for sure ... documentation is a bit confused.

Is there a way to do it ? Some another way to prevent this data transfer cost?

Thanks in advanced.

asked 2 years ago436 views

4 Answers
1

Hello.

If you set a route to the gateway-type VPC endpoint in the route table of the public subnet, you can access S3 via the VPC endpoint even if it is EC2 in the public subnet.
As described in the document below, routes are determined by the longest prefix match in the route table.
Therefore, if a route to the VPC endpoint is set in the route table, communication to S3 will be routed to the VPC endpoint even if it is a public subnet.
https://docs.aws.amazon.com/vpc/latest/privatelink/gateway-endpoints.html#gateway-endpoint-routing

  • We use the most specific route that matches the traffic to determine how to route the traffic (longest prefix match). For route tables with an endpoint route, this means the following:
    • If there is a route that sends all internet traffic (0.0.0.0/0) to an internet gateway, the endpoint route takes precedence for traffic destined for the service (Amazon S3 or DynamoDB) in the current Region. Traffic destined for a different AWS service uses the internet gateway.
    • Traffic that's destined for the service (Amazon S3 or DynamoDB) in a different Region goes to the internet gateway because prefix lists are specific to a Region.
    • If there is a route that specifies the exact IP address range for the service (Amazon S3 or DynamoDB) in the same Region, that route takes precedence over the endpoint route.
EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

AWS
EXPERT

reviewed 2 years ago

  • No, there is an option to select a route table when creating a gateway VPC endpoint. The route will be automatically added to the selected route table. Please select the route table to which you want to add routes when creating a gateway-type VPC endpoint using the steps in the document below. https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html#create-gateway-endpoint-s3

    For Route tables, select the route tables to be used by the endpoint. We automatically add a route that points traffic destined for the service to the endpoint network interface.

  • You can select a route table when creating a gateway VPC endpoint as shown in the image below. a

  • The route to the VPC endpoint is simply added to the selected route table, so EC2 will not be moved to the private subnet. The explanation you have circled in red is that the IP address used to access S3 from EC2 will change from a public IP address to a private IP address.

0

Thanks for answer.

Need i to add it here? If yes, which one?

  • look in attachments.

aws

aws

answered 2 years ago

0

Well if i understand it right, i Just need to select the route table (that cointain public subnets) when creating the vpc gateway s3 endpoint Then aws Will do it, right ?

answered 2 years ago

0

I'm afraid about this popup info in attach image (red marked). Very confused phase.

  • Looks like all instances that use subnets from this route table Will move to private, i didnt understand for sure.

aws

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.