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?
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:
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
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With