Does the AmazonS3 class from the AWS JavaSDK use the public internet to upload a file to an s3 bucket?

0

I am building a spring boot application that can upload images to an s3 bucket. When its finished it will run on an EC2 instance that is in the same region as my s3 buckets.

The sping boot application is using the AWS sdk for java to connect to and upload files to s3. The s3Client class that does the uploading is instantiated in the following way:

@Bean
public AmazonS3 s3client() {
    BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsId, awsKey);
    AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
            .withRegion(Regions.fromName(region))
            .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
            .withClientConfiguration(
            new ClientConfiguration()
                    .withMaxConnections(MAX_CONNECTIONS)
            .withMaxErrorRetry(3)
            )
            .build();
    return s3Client;
}

When I upload a file from localhost it must go through the public internet. But i want the s3Client to use the internal network of the AWS region once the application is running on EC2, simply because its a lot faster. My question is: Will the s3Client do this by default or do i need to configure it to use the internal network? If so, how do i do that?

Thanks

已提問 2 年前檢視次數 319 次
1 個回答
0
已接受的答案

Whether AWS API calls go via public internet or not is determined by your VPC networking setup - specifically VPC Endpoints. For the S3 service you can have either a Gateway or Interface VPC Endpoint. Generally a Gateway one is the way to go unless you need access to the endpoint from on-prem. So if your VPC is set up with an S3 Gateway VPC Endpoint and you have the appropriate route in your route tables, then any AWS API calls to S3 from your EC2 instance will stay on the AWS network.

專家
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南