By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Downloading PDF from s3 bucket takes too much time.

1

Currently I'm downloading Pdf from s3 bucket, fetching url from server side, then download pdf from url. it's working fine but takes too much time.

try { const response = await fetch(endpoint?agreement_id=${agreement_id}`, { method: 'GET', });

if (!response.ok) {
  throw new Error('Failed to fetch the agreement');
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `${agreement_id}.pdf`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);

} catch (error) { console.error("Error: ", error.message); }`

My question it how to make it faster? my internet connection speed is 30MBs.

2 Answers
0

To improve the download speed of PDFs from an S3 bucket, there are several strategies you can consider:

  1. Use Amazon S3 Transfer Acceleration: This service can significantly speed up content transfers to and from S3 by routing traffic through Amazon CloudFront's globally distributed edge locations. It's particularly beneficial for long-distance transfers and can help reduce latency.

  2. Implement multipart downloads: Instead of downloading the entire file at once, you can split the download into smaller chunks and download them concurrently. This approach can improve performance, especially for larger files.

  3. Optimize your Lambda function (if you're using one): If you're using a Lambda function to handle the download, consider increasing its memory allocation. This will proportionally increase the CPU power available, potentially improving download speed.

  4. Use parallel downloads: If you're downloading multiple files, you can implement concurrent downloads using techniques like Promise.all() or libraries that support parallel operations.

  5. Implement proper error handling and retries: Network issues can occur, so implementing a robust retry mechanism can help ensure successful downloads.

  6. Consider using a Content Delivery Network (CDN): If the PDFs are frequently accessed, using a CDN can help distribute the content closer to the users, reducing latency.

  7. Optimize your client-side code: Ensure you're using efficient methods for handling the downloaded data. For instance, you might want to stream the download directly to disk instead of loading it entirely into memory.

  8. Check your S3 bucket configuration: Ensure your bucket is in the same region as your application to minimize latency.

  9. Use the latest AWS SDK: The most recent versions of AWS SDKs often include performance improvements and optimizations.

  10. Monitor and analyze: Use AWS tools like CloudWatch to monitor your S3 performance and identify any bottlenecks.

Remember, the actual download speed will also depend on factors like the size of the PDF, your internet connection, and the current load on AWS services. It's important to test different approaches to find the best solution for your specific use case.
Sources
S3 Transfer Acceleration
Use Amazon S3 Transfer Acceleration to Minimize Latency Caused by Distance - Best Practices Design Patterns: Optimizing Amazon S3 Performance
Accessing S3 Objects takes time | AWS re:Post
Upload or download large files to and from Amazon S3 using an AWS SDK - Amazon Simple Storage Service

profile picture
answered 18 days ago
profile picture
EXPERT
reviewed 18 days ago
0

Just enable Transfer acceleration and using that endpoint to download. Here is my reason:

  • By default if you are using endpoint of S3 object, you fetch content via Internet, so that the passes through multiple network providers, routers, and nodes before reaching its destination. Each "hop" introduces latency due to routing, processing, and potential congestion at intermediate points
  • When you using Transfer Acceleration endpoint, it jump to nearest CloudFront Edge Locations, and go through AWS Backbone Network with lower latency.

How to use:

Go to S3 Console > Choose bucket > Properties > Transfer Acceleration > Enable

You will get the endpoint like this: https://<bucket-name>.s3-accelerate.amazonaws.com

Note that with this solution, it charge you for amount of data you transfer and is priced separately from standard S3 data transfer costs.

profile picture
answered 18 days 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.

Guidelines for Answering Questions