Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use S3 VPC endpoint in Java?

What is the way to get an S3 object using the VPC endpoint for S3 in JAVA? Shall I use a simple http-client? Or is there a way to do this using AmazonS3ClientBuilder?

like image 448
user3740951 Avatar asked Sep 06 '26 13:09

user3740951


2 Answers

You don't do anything differently when using an S3 VPC endpoint after you configure it. Nothing in your code changes.

When a subnet in a VPC is associated with a route table that is configured for a VPC endpoint, only one thing happens:

  • all of the public IP addresses for S3 in your region are routed to the VPC endpoint instead of following the default route.

That's it.

The prefix list pl-xxxxxxxx in your route table represents a list of all the public subnets associated with S3 in your region. The list is automatically maintained by the AWS infrastructure. When an instance sends traffic to S3, it does a DNS lookup to find an IP address for the bucket. When it connects to that IP address, if the route table for the instance's subnet includes an entry for that prefix list using the VPC endpoint for S3, it connects to S3 over the endpoint.

All instances in subnets associated with the specified route tables automatically use the endpoint to access the service; subnets that are not associated with the specified route tables do not use the endpoint to access the service.

http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-endpoints.html#vpc-endpoints-routing

like image 194
Michael - sqlbot Avatar answered Sep 08 '26 03:09

Michael - sqlbot


The AmazonS3ClientBuilder can be used to build a client that can connect to a specific end-point. There is no need to write your own low-level client!

Here's an example:

BasicAWSCredentials myCredentials = new BasicAWSCredentials("access_key", "secret_key");
AWSCredentialsProvider myCredentialsProvider = new StaticAWSCredentialsProvider(myCredentials);
String myEndpoint = ".."; // set your endpoint here
String myRegion = "..";   // set your region (ie. us-east-1, or us-east-1 etc.)

AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
            .withCredentials(myCredentialProvider)
            .withEndpoint(myEndpoint)
            .withRegion(myRegion)
            .build();
like image 28
Mike Dinescu Avatar answered Sep 08 '26 03:09

Mike Dinescu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!