How to troubleshoot and resolve slow access speed in S3 new Bucket?

131    Asked by Diyatomar in AWS , Asked on Jun 18, 2024

 I am a cloud engineer and I am currently working for a tech-based company that uses AWS for its storage needs. Recently, my team has set up a new S3 bucket in the Asia Pacific region (ap East 1) to store the critical application logs and user data. The bucket is named “my-bucket-s3-ap-east”. One day I received a notification that the users in that region were facing a slow speed of access time to my application, particularly when they were trying to retrieve the data in this new S3 bucket. How can I troubleshoot and resolve this particular issue? 

Answered by David WHITE

In the context of AWS, here are the steps given for how you can troubleshoot the issue:-

Checking S3 bucket Configuration

Try to ensure that the Bucket is configured correctly and has the necessary permission.

Network latency analysis

Try to use tools like AWS clouding to test the latency from various regions to the AP East region.

S3 metric and logs

You should try to enable and review the Amazon S3 server access logs to identify any patterns or anomalies.

Here is the solution given for the geographical latency:-

Amazon CloudFront distribution

You should set up a Cloudfront distribution with the S3 bucket as the origin to cache The content closer to users.

Amazon S3 transfer acceleration

You should enable the S3 transferred acceleration to optimise the data transfer speeds.

Additional optimizing strategies

Amazon elastic search

You can use the elastic search to cache the frequently accessed data.

Database read replicas

For the dynamic content, you can consider using the read replicas which are closer to your users.

Multi-region S3 bucket

You can use the S3 replication to create the replicas of your bucket in the different regions.

Here is the example given by using the java:-

Import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
Import software.amazon.awssdk.regions.Region;
Import software.amazon.awssdk.services.cloudfront.CloudFrontClient;
Import software.amazon.awssdk.services.cloudfront.model.CloudFrontOriginAccessIdentityConfig;
Import software.amazon.awssdk.services.cloudfront.model.CreateCloudFrontOriginAccessIdentityRequest;
Import software.amazon.awssdk.services.cloudfront.model.CreateCloudFrontOriginAccessIdentityResponse;
Import software.amazon.awssdk.services.cloudfront.model.CreateDistributionRequest;
Import software.amazon.awssdk.services.cloudfront.model.CreateDistributionResponse;
Import software.amazon.awssdk.services.cloudfront.model.DistributionConfig;
Import software.amazon.awssdk.services.cloudfront.model.Origins;
Import software.amazon.awssdk.services.cloudfront.model.S3OriginConfig;
Import software.amazon.awssdk.services.s3.S3Client;
Import software.amazon.awssdk.services.s3.model.*;
Import java.nio.file.Paths;
Public class S3CloudFrontExample {
    Private static final String BUCKET_NAME = “my-bucket-s3-ap-east”;
    Private static final Region REGION = Region.AP_EAST_1;
    Public static void main(String[] args) {
        S3Client s3Client = S3Client.builder()
                .region(REGION)
                .credentialsProvider(ProfileCredentialsProvider.create())
                .build();
        uploadFile(s3Client);
        enableTransferAcceleration(s3Client);
        createCloudFrontDistribution();
    }
    Private static void uploadFile(S3Client s3Client) {
        String filePath = “path/to/your/file.txt”;
        String key = “file.txt”;
        PutObjectRequest putObjectRequest = PutObjectRequest.builder()
                .bucket(BUCKET_NAME)
                .key(key)
                .build();
        S3Client.putObject(putObjectRequest, Paths.get(filePath));
        System.out.println(“File uploaded to S3 bucket: “ + BUCKET_NAME);
    }
    Private static void enableTransferAcceleration(S3Client s3Client) {
        PutBucketAccelerateConfigurationRequest accelerateConfigurationRequest =
                PutBucketAccelerateConfigurationRequest.builder()
                        .bucket(BUCKET_NAME)
                        .accelerateConfiguration(BucketAccelerateConfiguration.builder()
                                .status(BucketAccelerateStatus.ENABLED)
                                .build())
                        .build();
        S3Client.putBucketAccelerateConfiguration(accelerateConfigurationRequest);
        System.out.println(“Transfer Acceleration enabled on S3 bucket: “ + BUCKET_NAME);
    }
    Private static void createCloudFrontDistribution() {
        CloudFrontClient cloudFrontClient = CloudFrontClient.builder()
                .credentialsProvider(ProfileCredentialsProvider.create())
                .build();
        // Create CloudFront Origin Access Identity
        CloudFrontOriginAccessIdentityConfig originAccessIdentityConfig =
                CloudFrontOriginAccessIdentityConfig.builder()
                        .comment(“Access Identity for S3 bucket”)
                        .build();
        CreateCloudFrontOriginAccessIdentityRequest originAccessIdentityRequest =
                CreateCloudFrontOriginAccessIdentityRequest.builder()
                        .cloudFrontOriginAccessIdentityConfig(originAccessIdentityConfig)
                        .build();
        CreateCloudFrontOriginAccessIdentityResponse originAccessIdentityResponse =
                cloudFrontClient.createCloudFrontOriginAccessIdentity(originAccessIdentityRequest);
        String originAccessIdentityId = originAccessIdentityResponse
                .cloudFrontOriginAccessIdentity()
                .id();
        // Create CloudFront Distribution
        S3OriginConfig s3OriginConfig = S3OriginConfig.builder()
                .originAccessIdentity(“origin-access-identity/cloudfront/” + originAccessIdentityId)
                .build();
        Origins origins = Origins.builder()
                .items(Collections.singletonList(Origin.builder()
                        .domainName(BUCKET_NAME + “.s3.amazonaws.com”)
                        .id(BUCKET_NAME)
                        .s3OriginConfig(s3OriginConfig)
                        .build()))
                .quantity(1)
                .build();
        DistributionConfig distributionConfig = DistributionConfig.builder()
                .enabled(true)
                .origins(origins)
                .defaultRootObject(“index.html”)
                .build();
        CreateDistributionRequest distributionRequest = CreateDistributionRequest.builder()
                .distributionConfig(distributionConfig)
                .build();
        CreateDistributionResponse distributionResponse = cloudFrontClient.createDistribution(distributionRequest);
        System.out.println(“CloudFront distribution created: “ +
                distributionResponse.distribution().domainName());
    }
}


Your Answer

Interviews

Parent Categories