How to format a URL to get a file from Amazon S3?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Getting a file from Amazon S3 with a URL is straightforward once you separate two questions: what the object key is, and whether the object is public or private. Public objects can be addressed with a normal HTTPS URL, while private objects usually require a presigned URL generated through the AWS SDK.
Use the Virtual-Hosted-Style S3 URL
For a public object, the standard pattern is the virtual-hosted-style URL:
The important pieces are:
- the bucket name in the host name
- the AWS region in the host name
- the object key as the path
If the object key contains spaces or other reserved characters, URL-encode it instead of inserting the raw key string into the URL.
That avoids subtle bugs where a key works in SDK calls but fails in a browser or HTTP client because the URL path was not encoded correctly.
Do Not Confuse S3 URLs With s3:// Paths
The string s3://my-bucket/path/file.txt is an S3 URI, not a browser-download URL. It is useful for SDKs, CLI tools, and some data platforms, but a web browser cannot fetch it directly.
If you need an HTTP URL, format it as an HTTPS endpoint. If you need a programmatic object identifier for AWS tooling, use the s3:// form. Those two formats serve different purposes even though they point at the same object.
Use Presigned URLs for Private Files
Most production buckets are not public, so a hand-built HTTPS URL alone is not enough. In that case, generate a presigned URL that grants temporary access to the GetObject request.
This is the normal approach when the file should be downloaded by a user or service without exposing the whole bucket publicly.
Match the URL Style to the Endpoint You Actually Need
S3 has different endpoint types, including REST endpoints, website endpoints, and access-point-style endpoints. For ordinary object download, the REST-style virtual-hosted URL is the right default.
Static website endpoints are different. They are meant for website hosting behavior and are not interchangeable with authenticated object retrieval. If you are trying to download a private object, use the REST endpoint plus a presigned URL, not a website endpoint.
That distinction matters because the same object key can be addressable through different endpoint styles with very different permission rules.
Common Pitfalls
- Building a public HTTPS URL for an object that is private and then assuming the URL format is wrong when the real problem is permissions.
- Forgetting to URL-encode spaces or special characters in the object key.
- Pasting an
s3://URI into a browser and expecting it to behave like an HTTPS download URL. - Using the wrong region in the host name, which can lead to redirects or failed access.
- Mixing S3 website endpoints and normal object endpoints even though they serve different access patterns.
Summary
- Public S3 objects use an HTTPS URL with the bucket, region, and encoded object key.
- '
s3://is an AWS URI format, not a normal download URL.' - Private objects should usually be accessed with a presigned URL.
- URL-encode object keys before inserting them into a browser-facing URL.
- Choose the correct S3 endpoint type for the access pattern you need.
Related reading
- How to forward port in AWS Application load balancer ALB port forwarding
- How to Generate a Presigned S3 URL via AWS CLI
- How to generate a temporary url to upload file to Amazon S3 with boto library?
- How to generate access token for an AWS Cognito user?
- How to get a custom healthcheck path in a GCE L7 balancer serving a Kubernetes Ingress?
- How to get additional lines of context in a CloudWatch Insights query?
- How to get an AWS EC2 instance ID from within that EC2 instance?
- How to get arn of EC2 instance in AWS
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.